@pina-rs/amm 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/dist/index.cjs +1257 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1752 -0
- package/dist/index.d.ts +1752 -0
- package/dist/index.js +1078 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -8
- package/src/generated/accounts/ammConfig.ts +197 -0
- package/src/generated/accounts/index.ts +10 -0
- package/src/generated/accounts/pool.ts +218 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/pinaAmm.ts +64 -0
- package/src/generated/events/feesCollected.ts +64 -0
- package/src/generated/events/index.ts +13 -0
- package/src/generated/events/liquidityChanged.ts +72 -0
- package/src/generated/events/logs.ts +372 -0
- package/src/generated/events/poolCreated.ts +80 -0
- package/src/generated/events/swapped.ts +100 -0
- package/src/generated/index.ts +14 -0
- package/src/generated/instructions/collectCreatorFees.ts +119 -0
- package/src/generated/instructions/collectProtocolFees.ts +123 -0
- package/src/generated/instructions/createConfig.ts +142 -0
- package/src/generated/instructions/createPool.ts +291 -0
- package/src/generated/instructions/deposit.ts +139 -0
- package/src/generated/instructions/index.ts +19 -0
- package/src/generated/instructions/migrate.ts +155 -0
- package/src/generated/instructions/setPoolCreator.ts +90 -0
- package/src/generated/instructions/swapExactIn.ts +119 -0
- package/src/generated/instructions/swapExactOut.ts +119 -0
- package/src/generated/instructions/updateConfig.ts +105 -0
- package/src/generated/instructions/withdraw.ts +139 -0
- package/src/generated/pdas/ammConfig.ts +18 -0
- package/src/generated/pdas/index.ts +12 -0
- package/src/generated/pdas/pool.ts +20 -0
- package/src/generated/pdas/poolLpMint.ts +18 -0
- package/src/generated/pdas/poolVault.ts +19 -0
- package/src/generated/pinaPodCodecs.ts +232 -0
- package/src/generated/programs/index.ts +9 -0
- package/src/generated/programs/pinaAmm.ts +115 -0
- package/src/index.ts +11 -0
- package/CHANGELOG.md +0 -5
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getPinaPodDiscriminatorDecoder } from "../pinaPodCodecs";
|
|
10
|
+
import { combineCodec, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type WritableAccount } from '@solana/kit';
|
|
11
|
+
import { getAccountMetaFactory, type InstructionAccountInput, type InstructionAccountInputAddress, type InstructionSignerInput, type ResolvedInstructionAccount, type ResolvedInstructionAccountMeta } from '@solana/program-client-core';
|
|
12
|
+
import { PINA_AMM_PROGRAM_ADDRESS } from '../programs';
|
|
13
|
+
|
|
14
|
+
export const WITHDRAW_DISCRIMINATOR = 4;
|
|
15
|
+
|
|
16
|
+
export function getWithdrawDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(WITHDRAW_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type WithdrawInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountOwner extends string | AccountMeta<string> = string, TAccountPool extends string | AccountMeta<string> = string, TAccountVault0 extends string | AccountMeta<string> = string, TAccountVault1 extends string | AccountMeta<string> = string, TAccountLpMint extends string | AccountMeta<string> = string, TAccountOwnerToken0 extends string | AccountMeta<string> = string, TAccountOwnerToken1 extends string | AccountMeta<string> = string, TAccountOwnerLpToken extends string | AccountMeta<string> = string, TAccountTokenProgram0 extends string | AccountMeta<string> = string, TAccountTokenProgram1 extends string | AccountMeta<string> = string, TAccountLpTokenProgram extends string | AccountMeta<string> = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountOwner extends string ? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner> : TAccountOwner, TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool, TAccountVault0 extends string ? WritableAccount<TAccountVault0> : TAccountVault0, TAccountVault1 extends string ? WritableAccount<TAccountVault1> : TAccountVault1, TAccountLpMint extends string ? WritableAccount<TAccountLpMint> : TAccountLpMint, TAccountOwnerToken0 extends string ? WritableAccount<TAccountOwnerToken0> : TAccountOwnerToken0, TAccountOwnerToken1 extends string ? WritableAccount<TAccountOwnerToken1> : TAccountOwnerToken1, TAccountOwnerLpToken extends string ? WritableAccount<TAccountOwnerLpToken> : TAccountOwnerLpToken, TAccountTokenProgram0 extends string ? ReadonlyAccount<TAccountTokenProgram0> : TAccountTokenProgram0, TAccountTokenProgram1 extends string ? ReadonlyAccount<TAccountTokenProgram1> : TAccountTokenProgram1, TAccountLpTokenProgram extends string ? ReadonlyAccount<TAccountLpTokenProgram> : TAccountLpTokenProgram, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type WithdrawInstructionData = { discriminator: number;
|
|
22
|
+
/** LP to burn. */
|
|
23
|
+
lpAmount: bigint;
|
|
24
|
+
/** Least token 0 the owner will accept. */
|
|
25
|
+
minimumAmount0: bigint;
|
|
26
|
+
/** Least token 1 the owner will accept. */
|
|
27
|
+
minimumAmount1: bigint; };
|
|
28
|
+
|
|
29
|
+
export type WithdrawInstructionDataArgs = {
|
|
30
|
+
/** LP to burn. */
|
|
31
|
+
lpAmount: number | bigint;
|
|
32
|
+
/** Least token 0 the owner will accept. */
|
|
33
|
+
minimumAmount0: number | bigint;
|
|
34
|
+
/** Least token 1 the owner will accept. */
|
|
35
|
+
minimumAmount1: number | bigint; };
|
|
36
|
+
|
|
37
|
+
export function getWithdrawInstructionDataEncoder(): FixedSizeEncoder<WithdrawInstructionDataArgs> {
|
|
38
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['lpAmount', getU64Encoder()], ['minimumAmount0', getU64Encoder()], ['minimumAmount1', getU64Encoder()]]), (value) => ({ ...value, discriminator: 4 }));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getWithdrawInstructionDataDecoder(): FixedSizeDecoder<WithdrawInstructionData> {
|
|
42
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(WITHDRAW_DISCRIMINATOR, getU8Decoder())], ['lpAmount', getU64Decoder()], ['minimumAmount0', getU64Decoder()], ['minimumAmount1', getU64Decoder()]]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getWithdrawInstructionDataCodec(): FixedSizeCodec<WithdrawInstructionDataArgs, WithdrawInstructionData> {
|
|
46
|
+
return combineCodec(getWithdrawInstructionDataEncoder(), getWithdrawInstructionDataDecoder());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type WithdrawInput<TAccountOwner extends InstructionSignerInput = InstructionSignerInput, TAccountPool extends InstructionAccountInput = InstructionAccountInput, TAccountVault0 extends InstructionAccountInput = InstructionAccountInput, TAccountVault1 extends InstructionAccountInput = InstructionAccountInput, TAccountLpMint extends InstructionAccountInput = InstructionAccountInput, TAccountOwnerToken0 extends InstructionAccountInput = InstructionAccountInput, TAccountOwnerToken1 extends InstructionAccountInput = InstructionAccountInput, TAccountOwnerLpToken extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput = InstructionAccountInput, TAccountLpTokenProgram extends InstructionAccountInput = InstructionAccountInput> = {
|
|
50
|
+
/** The LP owner, who owns every token account below. */
|
|
51
|
+
owner: TAccountOwner;
|
|
52
|
+
/** The pool. */
|
|
53
|
+
pool: TAccountPool;
|
|
54
|
+
/** The pool's token 0 vault. */
|
|
55
|
+
vault0: TAccountVault0;
|
|
56
|
+
/** The pool's token 1 vault. */
|
|
57
|
+
vault1: TAccountVault1;
|
|
58
|
+
/** The pool's LP mint. */
|
|
59
|
+
lpMint: TAccountLpMint;
|
|
60
|
+
/** The owner's token 0 account. */
|
|
61
|
+
ownerToken0: TAccountOwnerToken0;
|
|
62
|
+
/** The owner's token 1 account. */
|
|
63
|
+
ownerToken1: TAccountOwnerToken1;
|
|
64
|
+
/** The owner's LP token account. */
|
|
65
|
+
ownerLpToken: TAccountOwnerLpToken;
|
|
66
|
+
/** Token program that owns token 0. */
|
|
67
|
+
tokenProgram0: TAccountTokenProgram0;
|
|
68
|
+
/** Token program that owns token 1. */
|
|
69
|
+
tokenProgram1: TAccountTokenProgram1;
|
|
70
|
+
/** SPL Token, which owns every LP mint. */
|
|
71
|
+
lpTokenProgram?: TAccountLpTokenProgram;
|
|
72
|
+
lpAmount: WithdrawInstructionDataArgs["lpAmount"];
|
|
73
|
+
minimumAmount0: WithdrawInstructionDataArgs["minimumAmount0"];
|
|
74
|
+
minimumAmount1: WithdrawInstructionDataArgs["minimumAmount1"];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getWithdrawInstruction<TAccountOwner extends InstructionSignerInput, TAccountPool extends InstructionAccountInput, TAccountVault0 extends InstructionAccountInput, TAccountVault1 extends InstructionAccountInput, TAccountLpMint extends InstructionAccountInput, TAccountOwnerToken0 extends InstructionAccountInput, TAccountOwnerToken1 extends InstructionAccountInput, TAccountOwnerLpToken extends InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput, TAccountLpTokenProgram extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: WithdrawInput<TAccountOwner, TAccountPool, TAccountVault0, TAccountVault1, TAccountLpMint, TAccountOwnerToken0, TAccountOwnerToken1, TAccountOwnerLpToken, TAccountTokenProgram0, TAccountTokenProgram1, TAccountLpTokenProgram>, config?: { programAddress?: TProgramAddress } ): WithdrawInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountOwner, InstructionAccountInputAddress<TAccountOwner>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountLpMint, InstructionAccountInputAddress<TAccountLpMint>>, ResolvedInstructionAccountMeta<TAccountOwnerToken0, InstructionAccountInputAddress<TAccountOwnerToken0>>, ResolvedInstructionAccountMeta<TAccountOwnerToken1, InstructionAccountInputAddress<TAccountOwnerToken1>>, ResolvedInstructionAccountMeta<TAccountOwnerLpToken, InstructionAccountInputAddress<TAccountOwnerLpToken>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>, ResolvedInstructionAccountMeta<TAccountLpTokenProgram, InstructionAccountInputAddress<TAccountLpTokenProgram>>> {
|
|
78
|
+
// Program address.
|
|
79
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
80
|
+
|
|
81
|
+
// Account meta helper.
|
|
82
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
83
|
+
|
|
84
|
+
// Original accounts.
|
|
85
|
+
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 } }
|
|
86
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// Original args.
|
|
90
|
+
const args = { ...input, };
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// Resolve default values.
|
|
94
|
+
if (!accounts.lpTokenProgram.value) {
|
|
95
|
+
accounts.lpTokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
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 as WithdrawInstructionDataArgs), programAddress } as WithdrawInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountOwner, InstructionAccountInputAddress<TAccountOwner>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountLpMint, InstructionAccountInputAddress<TAccountLpMint>>, ResolvedInstructionAccountMeta<TAccountOwnerToken0, InstructionAccountInputAddress<TAccountOwnerToken0>>, ResolvedInstructionAccountMeta<TAccountOwnerToken1, InstructionAccountInputAddress<TAccountOwnerToken1>>, ResolvedInstructionAccountMeta<TAccountOwnerLpToken, InstructionAccountInputAddress<TAccountOwnerLpToken>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>, ResolvedInstructionAccountMeta<TAccountLpTokenProgram, InstructionAccountInputAddress<TAccountLpTokenProgram>>>);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type ParsedWithdrawInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
102
|
+
accounts: {
|
|
103
|
+
/** The LP owner, who owns every token account below. */
|
|
104
|
+
owner: TAccountMetas[0];
|
|
105
|
+
/** The pool. */
|
|
106
|
+
pool: TAccountMetas[1];
|
|
107
|
+
/** The pool's token 0 vault. */
|
|
108
|
+
vault0: TAccountMetas[2];
|
|
109
|
+
/** The pool's token 1 vault. */
|
|
110
|
+
vault1: TAccountMetas[3];
|
|
111
|
+
/** The pool's LP mint. */
|
|
112
|
+
lpMint: TAccountMetas[4];
|
|
113
|
+
/** The owner's token 0 account. */
|
|
114
|
+
ownerToken0: TAccountMetas[5];
|
|
115
|
+
/** The owner's token 1 account. */
|
|
116
|
+
ownerToken1: TAccountMetas[6];
|
|
117
|
+
/** The owner's LP token account. */
|
|
118
|
+
ownerLpToken: TAccountMetas[7];
|
|
119
|
+
/** Token program that owns token 0. */
|
|
120
|
+
tokenProgram0: TAccountMetas[8];
|
|
121
|
+
/** Token program that owns token 1. */
|
|
122
|
+
tokenProgram1: TAccountMetas[9];
|
|
123
|
+
/** SPL Token, which owns every LP mint. */
|
|
124
|
+
lpTokenProgram: TAccountMetas[10];
|
|
125
|
+
};
|
|
126
|
+
data: WithdrawInstructionData; };
|
|
127
|
+
|
|
128
|
+
export function parseWithdrawInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedWithdrawInstruction<TProgram, TAccountMetas> {
|
|
129
|
+
if (instruction.accounts.length < 11) {
|
|
130
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11 });
|
|
131
|
+
}
|
|
132
|
+
let accountIndex = 0;
|
|
133
|
+
const getNextAccount = () => {
|
|
134
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
135
|
+
accountIndex += 1;
|
|
136
|
+
return accountMeta;
|
|
137
|
+
}
|
|
138
|
+
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) };
|
|
139
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { getProgramDerivedAddress, getU16Encoder, getUtf8Encoder, type Address, type ProgramDerivedAddress } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type AmmConfigSeeds = {
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export async function findAmmConfigPda(seeds: AmmConfigSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
16
|
+
const { programAddress = 'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV' as Address<'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV'> } = config;
|
|
17
|
+
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("amm_config"), getU16Encoder().encode(seeds.index)]});
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from './ammConfig';
|
|
10
|
+
export * from './pool';
|
|
11
|
+
export * from './poolLpMint';
|
|
12
|
+
export * from './poolVault';
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { getAddressEncoder, getProgramDerivedAddress, getUtf8Encoder, type Address, type ProgramDerivedAddress } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type PoolSeeds = {
|
|
12
|
+
ammConfig: Address;
|
|
13
|
+
mint0: Address;
|
|
14
|
+
mint1: Address;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function findPoolPda(seeds: PoolSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
18
|
+
const { programAddress = 'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV' as Address<'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV'> } = config;
|
|
19
|
+
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool"), getAddressEncoder().encode(seeds.ammConfig), getAddressEncoder().encode(seeds.mint0), getAddressEncoder().encode(seeds.mint1)]});
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { getAddressEncoder, getProgramDerivedAddress, getUtf8Encoder, type Address, type ProgramDerivedAddress } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type PoolLpMintSeeds = {
|
|
12
|
+
pool: Address;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export async function findPoolLpMintPda(seeds: PoolLpMintSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
16
|
+
const { programAddress = 'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV' as Address<'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV'> } = config;
|
|
17
|
+
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool_lp_mint"), getAddressEncoder().encode(seeds.pool)]});
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { getAddressEncoder, getProgramDerivedAddress, getUtf8Encoder, type Address, type ProgramDerivedAddress } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type PoolVaultSeeds = {
|
|
12
|
+
pool: Address;
|
|
13
|
+
mint: Address;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function findPoolVaultPda(seeds: PoolVaultSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
17
|
+
const { programAddress = 'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV' as Address<'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV'> } = config;
|
|
18
|
+
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool_vault"), getAddressEncoder().encode(seeds.pool), getAddressEncoder().encode(seeds.mint)]});
|
|
19
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime validation for Pina's PinaPod wire types.
|
|
3
|
+
*
|
|
4
|
+
* This file is generated by `pina generate`. The stock Codama codecs
|
|
5
|
+
* intentionally permit truncation and permissive decoding, whereas Pina's
|
|
6
|
+
* on-chain PinaPod views reject those non-canonical representations.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type Decoder,
|
|
11
|
+
type Encoder,
|
|
12
|
+
type FixedSizeDecoder,
|
|
13
|
+
type FixedSizeEncoder,
|
|
14
|
+
addDecoderSizePrefix,
|
|
15
|
+
createDecoder,
|
|
16
|
+
fixDecoderSize,
|
|
17
|
+
fixEncoderSize,
|
|
18
|
+
getBytesDecoder,
|
|
19
|
+
getU8Decoder,
|
|
20
|
+
transformDecoder,
|
|
21
|
+
transformEncoder,
|
|
22
|
+
} from "@solana/kit";
|
|
23
|
+
|
|
24
|
+
type Integer = bigint | number;
|
|
25
|
+
type PinaPodCollection = { readonly length: number };
|
|
26
|
+
|
|
27
|
+
function assertPinaPodString(value: string, capacity: number): void {
|
|
28
|
+
const bytes = new TextEncoder().encode(value);
|
|
29
|
+
if (bytes.length > capacity) {
|
|
30
|
+
throw new RangeError(
|
|
31
|
+
`PinaPod string needs ${bytes.length} UTF-8 bytes but its capacity is ${capacity}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (new TextDecoder("utf-8", { fatal: true }).decode(bytes) !== value) {
|
|
35
|
+
throw new TypeError("PinaPod strings must contain valid Unicode scalar values");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Rejects an oversized collection before its item encoder runs. */
|
|
40
|
+
export function getPinaPodBoundedArrayEncoder<TFrom extends PinaPodCollection>(
|
|
41
|
+
encoder: Encoder<TFrom>,
|
|
42
|
+
capacity: number,
|
|
43
|
+
): Encoder<TFrom> {
|
|
44
|
+
return transformEncoder(encoder, (value) => {
|
|
45
|
+
if (value.length > capacity) {
|
|
46
|
+
throw new RangeError(
|
|
47
|
+
`PinaPod collection has ${value.length} items but its capacity is ${capacity}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Rejects a decoded collection that exceeds its schema capacity. */
|
|
55
|
+
export function getPinaPodBoundedArrayDecoder<
|
|
56
|
+
TTo extends PinaPodCollection,
|
|
57
|
+
TCount extends Integer,
|
|
58
|
+
>(
|
|
59
|
+
decoder: Decoder<TTo>,
|
|
60
|
+
countDecoder: Decoder<TCount>,
|
|
61
|
+
capacity: number,
|
|
62
|
+
): Decoder<TTo> {
|
|
63
|
+
return createDecoder({
|
|
64
|
+
...decoder,
|
|
65
|
+
read: (bytes, offset) => {
|
|
66
|
+
// Security: Codama's array decoder skips its size decoder at end-of-input.
|
|
67
|
+
// Read the shared header count first so an empty tail cannot hide a nonzero count.
|
|
68
|
+
countDecoder.read(bytes, offset);
|
|
69
|
+
const [value, newOffset] = decoder.read(bytes, offset);
|
|
70
|
+
if (value.length > capacity) {
|
|
71
|
+
throw new RangeError(
|
|
72
|
+
`PinaPod collection has ${value.length} items but its capacity is ${capacity}`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return [value, newOffset];
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Rejects an oversized count before the array decoder allocates or reads items. */
|
|
82
|
+
export function getPinaPodBoundedCountDecoder<TDecoded extends Integer>(
|
|
83
|
+
decoder: Decoder<TDecoded>,
|
|
84
|
+
capacity: number,
|
|
85
|
+
): Decoder<TDecoded> {
|
|
86
|
+
return transformDecoder(decoder, (value) => {
|
|
87
|
+
if (BigInt(value) > BigInt(capacity)) {
|
|
88
|
+
throw new RangeError(
|
|
89
|
+
`PinaPod collection count ${value} exceeds its capacity ${capacity}`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Enforces a string's UTF-8 byte capacity before its encoder runs. */
|
|
97
|
+
export function getPinaPodBoundedStringEncoder(
|
|
98
|
+
encoder: Encoder<string>,
|
|
99
|
+
capacity: number,
|
|
100
|
+
): Encoder<string> {
|
|
101
|
+
return transformEncoder(encoder, (value) => {
|
|
102
|
+
assertPinaPodString(value, capacity);
|
|
103
|
+
return value;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Defensively rechecks a decoded string's UTF-8 byte capacity. */
|
|
108
|
+
export function getPinaPodBoundedStringDecoder(
|
|
109
|
+
decoder: Decoder<string>,
|
|
110
|
+
capacity: number,
|
|
111
|
+
): Decoder<string> {
|
|
112
|
+
return transformDecoder(decoder, (value) => {
|
|
113
|
+
assertPinaPodString(value, capacity);
|
|
114
|
+
return value;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Decodes variable-size UTF-8 strictly instead of replacing malformed input. */
|
|
119
|
+
export function getPinaPodUtf8Decoder(): Decoder<string> {
|
|
120
|
+
return transformDecoder(getBytesDecoder(), (value) =>
|
|
121
|
+
new TextDecoder("utf-8", { fatal: true }).decode(value)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Pads valid values but rejects values that would otherwise be truncated. */
|
|
126
|
+
export function fixPinaPodEncoderSize<TFrom, TSize extends number>(
|
|
127
|
+
encoder: Encoder<TFrom>,
|
|
128
|
+
fixedBytes: TSize,
|
|
129
|
+
): FixedSizeEncoder<TFrom, TSize> {
|
|
130
|
+
const checkedEncoder = transformEncoder(encoder, (value: TFrom) => {
|
|
131
|
+
const encodedSize = "fixedSize" in encoder
|
|
132
|
+
? encoder.fixedSize
|
|
133
|
+
: encoder.getSizeFromValue(value);
|
|
134
|
+
if (encodedSize > fixedBytes) {
|
|
135
|
+
throw new RangeError(
|
|
136
|
+
`PinaPod value needs ${encodedSize} bytes but its capacity is ${fixedBytes}`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return fixEncoderSize(checkedEncoder, fixedBytes);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Decodes UTF-8 strictly and preserves embedded NUL characters. */
|
|
146
|
+
export function getPinaPodStringDecoder<TSize extends number>(
|
|
147
|
+
prefix: FixedSizeDecoder<bigint> | FixedSizeDecoder<number>,
|
|
148
|
+
fixedBytes: TSize,
|
|
149
|
+
): FixedSizeDecoder<string, TSize> {
|
|
150
|
+
const bytes = addDecoderSizePrefix(getBytesDecoder(), prefix);
|
|
151
|
+
return transformDecoder(fixDecoderSize(bytes, fixedBytes), (value) =>
|
|
152
|
+
new TextDecoder("utf-8", { fatal: true }).decode(value)
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Accepts only PinaPod's canonical boolean encodings. */
|
|
157
|
+
export function getPinaPodBooleanDecoder(): FixedSizeDecoder<boolean, 1> {
|
|
158
|
+
return transformDecoder(getU8Decoder(), (value) => {
|
|
159
|
+
if (value !== 0 && value !== 1) {
|
|
160
|
+
throw new RangeError(`invalid PinaPod boolean: ${value}`);
|
|
161
|
+
}
|
|
162
|
+
return value === 1;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Accepts only PinaPod's `None` and `Some` option tags. */
|
|
167
|
+
export function getPinaPodOptionTagDecoder<
|
|
168
|
+
TDecoded extends Integer,
|
|
169
|
+
TSize extends number,
|
|
170
|
+
>(
|
|
171
|
+
decoder: FixedSizeDecoder<TDecoded, TSize>,
|
|
172
|
+
): FixedSizeDecoder<TDecoded, TSize> {
|
|
173
|
+
return transformDecoder(decoder, (value) => {
|
|
174
|
+
if (BigInt(value) !== 0n && BigInt(value) !== 1n) {
|
|
175
|
+
throw new RangeError(`invalid PinaPod option tag: ${value}`);
|
|
176
|
+
}
|
|
177
|
+
return value;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Rejects data for a different account or instruction before decoding it. */
|
|
182
|
+
export function getPinaPodDiscriminatorDecoder<
|
|
183
|
+
TDecoded extends Integer,
|
|
184
|
+
TSize extends number,
|
|
185
|
+
>(
|
|
186
|
+
expected: Integer,
|
|
187
|
+
decoder: FixedSizeDecoder<TDecoded, TSize>,
|
|
188
|
+
): FixedSizeDecoder<TDecoded, TSize> {
|
|
189
|
+
return transformDecoder(decoder, (value) => {
|
|
190
|
+
if (BigInt(value) !== BigInt(expected)) {
|
|
191
|
+
throw new RangeError(
|
|
192
|
+
`invalid discriminator: expected ${expected}, received ${value}`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return value;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Rejects account or instruction data from another migration version. */
|
|
200
|
+
export function getPinaPodMigrationVersionDecoder<
|
|
201
|
+
TDecoded extends Integer,
|
|
202
|
+
TSize extends number,
|
|
203
|
+
>(
|
|
204
|
+
expected: Integer,
|
|
205
|
+
decoder: FixedSizeDecoder<TDecoded, TSize>,
|
|
206
|
+
): FixedSizeDecoder<TDecoded, TSize> {
|
|
207
|
+
return transformDecoder(decoder, (value) => {
|
|
208
|
+
if (BigInt(value) !== BigInt(expected)) {
|
|
209
|
+
const hint =
|
|
210
|
+
BigInt(value) < BigInt(expected)
|
|
211
|
+
? "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"
|
|
212
|
+
: "the data was written by a newer program; upgrade this client";
|
|
213
|
+
throw new RangeError(
|
|
214
|
+
`migration version mismatch: expected ${expected}, received ${value} (${hint})`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return value;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Rejects numeric enum representations not declared by the native schema. */
|
|
222
|
+
export function getPinaPodEnumDecoder<TValue extends number, TSize extends number>(
|
|
223
|
+
decoder: FixedSizeDecoder<TValue, TSize>,
|
|
224
|
+
validValues: readonly TValue[],
|
|
225
|
+
): FixedSizeDecoder<TValue, TSize> {
|
|
226
|
+
return transformDecoder(decoder, (value) => {
|
|
227
|
+
if (!validValues.includes(value)) {
|
|
228
|
+
throw new RangeError(`invalid PinaPod enum discriminant: ${value}`);
|
|
229
|
+
}
|
|
230
|
+
return value;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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, getUpdateConfigInstruction, getWithdrawInstruction, parseCollectCreatorFeesInstruction, parseCollectProtocolFeesInstruction, parseCreateConfigInstruction, parseCreatePoolInstruction, parseDepositInstruction, parseSetPoolCreatorInstruction, parseSwapExactInInstruction, parseSwapExactOutInstruction, 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 ParsedUpdateConfigInstruction, type ParsedWithdrawInstruction, type SetPoolCreatorInput, type SwapExactInInput, type SwapExactOutInput, 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 = 'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV' as Address<'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV'>;
|
|
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(0), 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 }
|
|
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
|
+
throw new Error('The provided event could not be identified as a pinaAmm event.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export enum PinaAmmInstruction { CreateConfig, UpdateConfig, CreatePool, Deposit, Withdraw, SwapExactIn, SwapExactOut, CollectProtocolFees, CollectCreatorFees, SetPoolCreator }
|
|
40
|
+
|
|
41
|
+
export function identifyPinaAmmInstruction(instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmInstruction {
|
|
42
|
+
const data = 'data' in instruction ? instruction.data : instruction;
|
|
43
|
+
if (containsBytes(data, getU8Encoder().encode(0), 0)) { return PinaAmmInstruction.CreateConfig; }
|
|
44
|
+
if (containsBytes(data, getU8Encoder().encode(1), 0)) { return PinaAmmInstruction.UpdateConfig; }
|
|
45
|
+
if (containsBytes(data, getU8Encoder().encode(2), 0)) { return PinaAmmInstruction.CreatePool; }
|
|
46
|
+
if (containsBytes(data, getU8Encoder().encode(3), 0)) { return PinaAmmInstruction.Deposit; }
|
|
47
|
+
if (containsBytes(data, getU8Encoder().encode(4), 0)) { return PinaAmmInstruction.Withdraw; }
|
|
48
|
+
if (containsBytes(data, getU8Encoder().encode(5), 0)) { return PinaAmmInstruction.SwapExactIn; }
|
|
49
|
+
if (containsBytes(data, getU8Encoder().encode(6), 0)) { return PinaAmmInstruction.SwapExactOut; }
|
|
50
|
+
if (containsBytes(data, getU8Encoder().encode(7), 0)) { return PinaAmmInstruction.CollectProtocolFees; }
|
|
51
|
+
if (containsBytes(data, getU8Encoder().encode(8), 0)) { return PinaAmmInstruction.CollectCreatorFees; }
|
|
52
|
+
if (containsBytes(data, getU8Encoder().encode(9), 0)) { return PinaAmmInstruction.SetPoolCreator; }
|
|
53
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "pinaAmm" });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type ParsedPinaAmmInstruction<TProgram extends string = 'pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV'> =
|
|
57
|
+
| { instructionType: PinaAmmInstruction.CreateConfig } & ParsedCreateConfigInstruction<TProgram>
|
|
58
|
+
| { instructionType: PinaAmmInstruction.UpdateConfig } & ParsedUpdateConfigInstruction<TProgram>
|
|
59
|
+
| { instructionType: PinaAmmInstruction.CreatePool } & ParsedCreatePoolInstruction<TProgram>
|
|
60
|
+
| { instructionType: PinaAmmInstruction.Deposit } & ParsedDepositInstruction<TProgram>
|
|
61
|
+
| { instructionType: PinaAmmInstruction.Withdraw } & ParsedWithdrawInstruction<TProgram>
|
|
62
|
+
| { instructionType: PinaAmmInstruction.SwapExactIn } & ParsedSwapExactInInstruction<TProgram>
|
|
63
|
+
| { instructionType: PinaAmmInstruction.SwapExactOut } & ParsedSwapExactOutInstruction<TProgram>
|
|
64
|
+
| { instructionType: PinaAmmInstruction.CollectProtocolFees } & ParsedCollectProtocolFeesInstruction<TProgram>
|
|
65
|
+
| { instructionType: PinaAmmInstruction.CollectCreatorFees } & ParsedCollectCreatorFeesInstruction<TProgram>
|
|
66
|
+
| { instructionType: PinaAmmInstruction.SetPoolCreator } & ParsedSetPoolCreatorInstruction<TProgram>
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export function parsePinaAmmInstruction<TProgram extends string>(
|
|
70
|
+
instruction: Instruction<TProgram>
|
|
71
|
+
& InstructionWithData<ReadonlyUint8Array>
|
|
72
|
+
): ParsedPinaAmmInstruction<TProgram> {
|
|
73
|
+
const instructionType = identifyPinaAmmInstruction(instruction);
|
|
74
|
+
switch (instructionType) {
|
|
75
|
+
case PinaAmmInstruction.CreateConfig: { assertIsInstructionWithAccounts(instruction);
|
|
76
|
+
return { instructionType: PinaAmmInstruction.CreateConfig, ...parseCreateConfigInstruction(instruction) }; }
|
|
77
|
+
case PinaAmmInstruction.UpdateConfig: { assertIsInstructionWithAccounts(instruction);
|
|
78
|
+
return { instructionType: PinaAmmInstruction.UpdateConfig, ...parseUpdateConfigInstruction(instruction) }; }
|
|
79
|
+
case PinaAmmInstruction.CreatePool: { assertIsInstructionWithAccounts(instruction);
|
|
80
|
+
return { instructionType: PinaAmmInstruction.CreatePool, ...parseCreatePoolInstruction(instruction) }; }
|
|
81
|
+
case PinaAmmInstruction.Deposit: { assertIsInstructionWithAccounts(instruction);
|
|
82
|
+
return { instructionType: PinaAmmInstruction.Deposit, ...parseDepositInstruction(instruction) }; }
|
|
83
|
+
case PinaAmmInstruction.Withdraw: { assertIsInstructionWithAccounts(instruction);
|
|
84
|
+
return { instructionType: PinaAmmInstruction.Withdraw, ...parseWithdrawInstruction(instruction) }; }
|
|
85
|
+
case PinaAmmInstruction.SwapExactIn: { assertIsInstructionWithAccounts(instruction);
|
|
86
|
+
return { instructionType: PinaAmmInstruction.SwapExactIn, ...parseSwapExactInInstruction(instruction) }; }
|
|
87
|
+
case PinaAmmInstruction.SwapExactOut: { assertIsInstructionWithAccounts(instruction);
|
|
88
|
+
return { instructionType: PinaAmmInstruction.SwapExactOut, ...parseSwapExactOutInstruction(instruction) }; }
|
|
89
|
+
case PinaAmmInstruction.CollectProtocolFees: { assertIsInstructionWithAccounts(instruction);
|
|
90
|
+
return { instructionType: PinaAmmInstruction.CollectProtocolFees, ...parseCollectProtocolFeesInstruction(instruction) }; }
|
|
91
|
+
case PinaAmmInstruction.CollectCreatorFees: { assertIsInstructionWithAccounts(instruction);
|
|
92
|
+
return { instructionType: PinaAmmInstruction.CollectCreatorFees, ...parseCollectCreatorFeesInstruction(instruction) }; }
|
|
93
|
+
case PinaAmmInstruction.SetPoolCreator: { assertIsInstructionWithAccounts(instruction);
|
|
94
|
+
return { instructionType: PinaAmmInstruction.SetPoolCreator, ...parseSetPoolCreatorInstruction(instruction) }; }
|
|
95
|
+
default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: "pinaAmm" });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type PinaAmmPlugin = { accounts: PinaAmmPluginAccounts; instructions: PinaAmmPluginInstructions; pdas: PinaAmmPluginPdas; identifyAccount: typeof identifyPinaAmmAccount; identifyInstruction: typeof identifyPinaAmmInstruction; parseInstruction: typeof parsePinaAmmInstruction; }
|
|
100
|
+
|
|
101
|
+
export type PinaAmmPluginAccounts = { ammConfig: ReturnType<typeof getAmmConfigCodec> & SelfFetchFunctions<AmmConfigArgs, AmmConfig>; pool: ReturnType<typeof getPoolCodec> & SelfFetchFunctions<PoolArgs, Pool>; }
|
|
102
|
+
|
|
103
|
+
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; }
|
|
104
|
+
|
|
105
|
+
export type PinaAmmPluginPdas = { ammConfig: typeof findAmmConfigPda; pool: typeof findPoolPda; poolVault: typeof findPoolVaultPda; poolLpMint: typeof findPoolLpMintPda; }
|
|
106
|
+
|
|
107
|
+
export type PinaAmmPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> & ClientWithTransactionPlanning & ClientWithTransactionSending
|
|
108
|
+
|
|
109
|
+
export function pinaAmmProgram() {
|
|
110
|
+
return <T extends PinaAmmPluginRequirements>(client: T): ExtendedClient<T, { pinaAmm: PinaAmmPlugin }> => {
|
|
111
|
+
return extendClient(client, { pinaAmm: <PinaAmmPlugin>{ accounts: { ammConfig: addSelfFetchFunctions(client, getAmmConfigCodec()), pool: addSelfFetchFunctions(client, getPoolCodec()) }, instructions: {
|
|
112
|
+
migrate: (input: MigrateInput) =>
|
|
113
|
+
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)) }, pdas: { ammConfig: findAmmConfigPda, pool: findPoolPda, poolVault: findPoolVaultPda, poolLpMint: findPoolLpMintPda }, identifyAccount: identifyPinaAmmAccount, identifyInstruction: identifyPinaAmmInstruction, parseInstruction: parsePinaAmmInstruction } });
|
|
114
|
+
};
|
|
115
|
+
}
|
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";
|