@pina-rs/amm 0.1.0 → 0.2.1
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/dist/index.cjs +501 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +451 -11
- package/dist/index.d.ts +451 -11
- package/dist/index.js +445 -16
- package/dist/index.js.map +1 -1
- package/package.json +59 -58
- package/src/generated/accounts/pool.ts +64 -8
- package/src/generated/errors/pinaAmm.ts +4 -2
- package/src/generated/events/configCreated.ts +80 -0
- package/src/generated/events/configUpdated.ts +64 -0
- package/src/generated/events/index.ts +5 -0
- package/src/generated/events/logs.ts +362 -2
- package/src/generated/events/poolCreatorChanged.ts +56 -0
- package/src/generated/events/poolSynced.ts +78 -0
- package/src/generated/events/poolSyncedV0.ts +44 -0
- package/src/generated/instructions/index.ts +1 -0
- package/src/generated/instructions/syncPool.ts +93 -0
- package/src/generated/pdas/ammConfig.ts +1 -1
- package/src/generated/pdas/pool.ts +1 -1
- package/src/generated/pdas/poolLpMint.ts +1 -1
- package/src/generated/pdas/poolVault.ts +1 -1
- package/src/generated/programs/pinaAmm.ts +17 -8
|
@@ -0,0 +1,93 @@
|
|
|
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, getU8Decoder, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount } from '@solana/kit';
|
|
11
|
+
import { getAccountMetaFactory, type InstructionAccountInput, type InstructionAccountInputAddress, type ResolvedInstructionAccount, type ResolvedInstructionAccountMeta } from '@solana/program-client-core';
|
|
12
|
+
import { PINA_AMM_PROGRAM_ADDRESS } from '../programs';
|
|
13
|
+
|
|
14
|
+
export const SYNC_POOL_DISCRIMINATOR = 10;
|
|
15
|
+
|
|
16
|
+
export function getSyncPoolDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SYNC_POOL_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type SyncPoolInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountPool extends string | AccountMeta<string> = string, TAccountVault0 extends string | AccountMeta<string> = string, TAccountVault1 extends string | AccountMeta<string> = string, TAccountTokenProgram0 extends string | AccountMeta<string> = string, TAccountTokenProgram1 extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool, TAccountVault0 extends string ? ReadonlyAccount<TAccountVault0> : TAccountVault0, TAccountVault1 extends string ? ReadonlyAccount<TAccountVault1> : TAccountVault1, TAccountTokenProgram0 extends string ? ReadonlyAccount<TAccountTokenProgram0> : TAccountTokenProgram0, TAccountTokenProgram1 extends string ? ReadonlyAccount<TAccountTokenProgram1> : TAccountTokenProgram1, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type SyncPoolInstructionData = { discriminator: number; };
|
|
22
|
+
|
|
23
|
+
export type SyncPoolInstructionDataArgs = { };
|
|
24
|
+
|
|
25
|
+
export function getSyncPoolInstructionDataEncoder(): FixedSizeEncoder<SyncPoolInstructionDataArgs> {
|
|
26
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), (value) => ({ ...value, discriminator: 10 }));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getSyncPoolInstructionDataDecoder(): FixedSizeDecoder<SyncPoolInstructionData> {
|
|
30
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(SYNC_POOL_DISCRIMINATOR, getU8Decoder())]]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getSyncPoolInstructionDataCodec(): FixedSizeCodec<SyncPoolInstructionDataArgs, SyncPoolInstructionData> {
|
|
34
|
+
return combineCodec(getSyncPoolInstructionDataEncoder(), getSyncPoolInstructionDataDecoder());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type SyncPoolInput<TAccountPool extends InstructionAccountInput = InstructionAccountInput, TAccountVault0 extends InstructionAccountInput = InstructionAccountInput, TAccountVault1 extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput = InstructionAccountInput> = {
|
|
38
|
+
/** The pool whose accumulator is advanced. */
|
|
39
|
+
pool: TAccountPool;
|
|
40
|
+
/** The pool's token 0 vault. */
|
|
41
|
+
vault0: TAccountVault0;
|
|
42
|
+
/** The pool's token 1 vault. */
|
|
43
|
+
vault1: TAccountVault1;
|
|
44
|
+
/** Token program that owns token 0. */
|
|
45
|
+
tokenProgram0: TAccountTokenProgram0;
|
|
46
|
+
/** Token program that owns token 1. */
|
|
47
|
+
tokenProgram1: TAccountTokenProgram1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getSyncPoolInstruction<TAccountPool extends InstructionAccountInput, TAccountVault0 extends InstructionAccountInput, TAccountVault1 extends InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: SyncPoolInput<TAccountPool, TAccountVault0, TAccountVault1, TAccountTokenProgram0, TAccountTokenProgram1>, config?: { programAddress?: TProgramAddress } ): SyncPoolInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>> {
|
|
51
|
+
// Program address.
|
|
52
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
53
|
+
|
|
54
|
+
// Account meta helper.
|
|
55
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
56
|
+
|
|
57
|
+
// Original accounts.
|
|
58
|
+
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 } }
|
|
59
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
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 } as SyncPoolInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>>);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ParsedSyncPoolInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
68
|
+
accounts: {
|
|
69
|
+
/** The pool whose accumulator is advanced. */
|
|
70
|
+
pool: TAccountMetas[0];
|
|
71
|
+
/** The pool's token 0 vault. */
|
|
72
|
+
vault0: TAccountMetas[1];
|
|
73
|
+
/** The pool's token 1 vault. */
|
|
74
|
+
vault1: TAccountMetas[2];
|
|
75
|
+
/** Token program that owns token 0. */
|
|
76
|
+
tokenProgram0: TAccountMetas[3];
|
|
77
|
+
/** Token program that owns token 1. */
|
|
78
|
+
tokenProgram1: TAccountMetas[4];
|
|
79
|
+
};
|
|
80
|
+
data: SyncPoolInstructionData; };
|
|
81
|
+
|
|
82
|
+
export function parseSyncPoolInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSyncPoolInstruction<TProgram, TAccountMetas> {
|
|
83
|
+
if (instruction.accounts.length < 5) {
|
|
84
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5 });
|
|
85
|
+
}
|
|
86
|
+
let accountIndex = 0;
|
|
87
|
+
const getNextAccount = () => {
|
|
88
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
89
|
+
accountIndex += 1;
|
|
90
|
+
return accountMeta;
|
|
91
|
+
}
|
|
92
|
+
return { programAddress: instruction.programAddress, accounts: { pool: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount() }, data: getSyncPoolInstructionDataDecoder().decode(instruction.data) };
|
|
93
|
+
}
|
|
@@ -13,6 +13,6 @@ index: number;
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export async function findAmmConfigPda(seeds: AmmConfigSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
16
|
-
const { programAddress = '
|
|
16
|
+
const { programAddress = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi' as Address<'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'> } = config;
|
|
17
17
|
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("amm_config"), getU16Encoder().encode(seeds.index)]});
|
|
18
18
|
}
|
|
@@ -15,6 +15,6 @@ mint1: Address;
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export async function findPoolPda(seeds: PoolSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
18
|
-
const { programAddress = '
|
|
18
|
+
const { programAddress = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi' as Address<'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'> } = config;
|
|
19
19
|
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool"), getAddressEncoder().encode(seeds.ammConfig), getAddressEncoder().encode(seeds.mint0), getAddressEncoder().encode(seeds.mint1)]});
|
|
20
20
|
}
|
|
@@ -13,6 +13,6 @@ pool: Address;
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export async function findPoolLpMintPda(seeds: PoolLpMintSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
16
|
-
const { programAddress = '
|
|
16
|
+
const { programAddress = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi' as Address<'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'> } = config;
|
|
17
17
|
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool_lp_mint"), getAddressEncoder().encode(seeds.pool)]});
|
|
18
18
|
}
|
|
@@ -14,6 +14,6 @@ mint: Address;
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export async function findPoolVaultPda(seeds: PoolVaultSeeds, config: { programAddress?: Address | undefined } = {}): Promise<ProgramDerivedAddress> {
|
|
17
|
-
const { programAddress = '
|
|
17
|
+
const { programAddress = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi' as Address<'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'> } = config;
|
|
18
18
|
return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool_vault"), getAddressEncoder().encode(seeds.pool), getAddressEncoder().encode(seeds.mint)]});
|
|
19
19
|
}
|
|
@@ -9,23 +9,23 @@
|
|
|
9
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
10
|
import { addSelfFetchFunctions, addSelfPlanAndSendFunctions, type SelfFetchFunctions, type SelfPlanAndSendFunctions } from '@solana/program-client-core';
|
|
11
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';
|
|
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
13
|
import { getMigrateInstruction, type MigrateInput } from "../instructions";
|
|
14
14
|
|
|
15
15
|
import { findAmmConfigPda, findPoolLpMintPda, findPoolPda, findPoolVaultPda } from '../pdas';
|
|
16
16
|
|
|
17
|
-
export const PINA_AMM_PROGRAM_ADDRESS = '
|
|
17
|
+
export const PINA_AMM_PROGRAM_ADDRESS = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi' as Address<'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'>;
|
|
18
18
|
|
|
19
19
|
export enum PinaAmmAccount { AmmConfig, Pool }
|
|
20
20
|
|
|
21
21
|
export function identifyPinaAmmAccount(account: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmAccount {
|
|
22
22
|
const data = 'data' in account ? account.data : account;
|
|
23
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(
|
|
24
|
+
if (containsBytes(data, getU8Encoder().encode(2), 0) && containsBytes(data, getU8Encoder().encode(1), 1)) { return PinaAmmAccount.Pool; }
|
|
25
25
|
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, { accountData: data, programName: "pinaAmm" });
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export enum PinaAmmEvent { PoolCreated, Swapped, LiquidityChanged, FeesCollected }
|
|
28
|
+
export enum PinaAmmEvent { PoolCreated, Swapped, LiquidityChanged, FeesCollected, PoolSynced, PoolSyncedV0, ConfigCreated, ConfigUpdated, PoolCreatorChanged }
|
|
29
29
|
|
|
30
30
|
export function identifyPinaAmmEvent(event: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmEvent {
|
|
31
31
|
const data = 'data' in event ? event.data : event;
|
|
@@ -33,10 +33,15 @@ export function identifyPinaAmmEvent(event: { data: ReadonlyUint8Array } | Reado
|
|
|
33
33
|
if (containsBytes(data, getU8Encoder().encode(2), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.Swapped; }
|
|
34
34
|
if (containsBytes(data, getU8Encoder().encode(3), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.LiquidityChanged; }
|
|
35
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; }
|
|
36
41
|
throw new Error('The provided event could not be identified as a pinaAmm event.');
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
export enum PinaAmmInstruction { CreateConfig, UpdateConfig, CreatePool, Deposit, Withdraw, SwapExactIn, SwapExactOut, CollectProtocolFees, CollectCreatorFees, SetPoolCreator }
|
|
44
|
+
export enum PinaAmmInstruction { CreateConfig, UpdateConfig, CreatePool, Deposit, Withdraw, SwapExactIn, SwapExactOut, CollectProtocolFees, CollectCreatorFees, SetPoolCreator, SyncPool }
|
|
40
45
|
|
|
41
46
|
export function identifyPinaAmmInstruction(instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmInstruction {
|
|
42
47
|
const data = 'data' in instruction ? instruction.data : instruction;
|
|
@@ -50,10 +55,11 @@ if (containsBytes(data, getU8Encoder().encode(6), 0)) { return PinaAmmInstructio
|
|
|
50
55
|
if (containsBytes(data, getU8Encoder().encode(7), 0)) { return PinaAmmInstruction.CollectProtocolFees; }
|
|
51
56
|
if (containsBytes(data, getU8Encoder().encode(8), 0)) { return PinaAmmInstruction.CollectCreatorFees; }
|
|
52
57
|
if (containsBytes(data, getU8Encoder().encode(9), 0)) { return PinaAmmInstruction.SetPoolCreator; }
|
|
58
|
+
if (containsBytes(data, getU8Encoder().encode(10), 0)) { return PinaAmmInstruction.SyncPool; }
|
|
53
59
|
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "pinaAmm" });
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
export type ParsedPinaAmmInstruction<TProgram extends string = '
|
|
62
|
+
export type ParsedPinaAmmInstruction<TProgram extends string = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'> =
|
|
57
63
|
| { instructionType: PinaAmmInstruction.CreateConfig } & ParsedCreateConfigInstruction<TProgram>
|
|
58
64
|
| { instructionType: PinaAmmInstruction.UpdateConfig } & ParsedUpdateConfigInstruction<TProgram>
|
|
59
65
|
| { instructionType: PinaAmmInstruction.CreatePool } & ParsedCreatePoolInstruction<TProgram>
|
|
@@ -64,6 +70,7 @@ export type ParsedPinaAmmInstruction<TProgram extends string = 'pAMMvXaqR2VVFqzn
|
|
|
64
70
|
| { instructionType: PinaAmmInstruction.CollectProtocolFees } & ParsedCollectProtocolFeesInstruction<TProgram>
|
|
65
71
|
| { instructionType: PinaAmmInstruction.CollectCreatorFees } & ParsedCollectCreatorFeesInstruction<TProgram>
|
|
66
72
|
| { instructionType: PinaAmmInstruction.SetPoolCreator } & ParsedSetPoolCreatorInstruction<TProgram>
|
|
73
|
+
| { instructionType: PinaAmmInstruction.SyncPool } & ParsedSyncPoolInstruction<TProgram>
|
|
67
74
|
|
|
68
75
|
|
|
69
76
|
export function parsePinaAmmInstruction<TProgram extends string>(
|
|
@@ -92,6 +99,8 @@ case PinaAmmInstruction.CollectCreatorFees: { assertIsInstructionWithAccounts(in
|
|
|
92
99
|
return { instructionType: PinaAmmInstruction.CollectCreatorFees, ...parseCollectCreatorFeesInstruction(instruction) }; }
|
|
93
100
|
case PinaAmmInstruction.SetPoolCreator: { assertIsInstructionWithAccounts(instruction);
|
|
94
101
|
return { instructionType: PinaAmmInstruction.SetPoolCreator, ...parseSetPoolCreatorInstruction(instruction) }; }
|
|
102
|
+
case PinaAmmInstruction.SyncPool: { assertIsInstructionWithAccounts(instruction);
|
|
103
|
+
return { instructionType: PinaAmmInstruction.SyncPool, ...parseSyncPoolInstruction(instruction) }; }
|
|
95
104
|
default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: "pinaAmm" });
|
|
96
105
|
}
|
|
97
106
|
}
|
|
@@ -100,7 +109,7 @@ export type PinaAmmPlugin = { accounts: PinaAmmPluginAccounts; instructions: Pin
|
|
|
100
109
|
|
|
101
110
|
export type PinaAmmPluginAccounts = { ammConfig: ReturnType<typeof getAmmConfigCodec> & SelfFetchFunctions<AmmConfigArgs, AmmConfig>; pool: ReturnType<typeof getPoolCodec> & SelfFetchFunctions<PoolArgs, Pool>; }
|
|
102
111
|
|
|
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; }
|
|
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; }
|
|
104
113
|
|
|
105
114
|
export type PinaAmmPluginPdas = { ammConfig: typeof findAmmConfigPda; pool: typeof findPoolPda; poolVault: typeof findPoolVaultPda; poolLpMint: typeof findPoolLpMintPda; }
|
|
106
115
|
|
|
@@ -110,6 +119,6 @@ export function pinaAmmProgram() {
|
|
|
110
119
|
return <T extends PinaAmmPluginRequirements>(client: T): ExtendedClient<T, { pinaAmm: PinaAmmPlugin }> => {
|
|
111
120
|
return extendClient(client, { pinaAmm: <PinaAmmPlugin>{ accounts: { ammConfig: addSelfFetchFunctions(client, getAmmConfigCodec()), pool: addSelfFetchFunctions(client, getPoolCodec()) }, instructions: {
|
|
112
121
|
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 } });
|
|
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 } });
|
|
114
123
|
};
|
|
115
124
|
}
|