@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.
- package/README.md +27 -2
- package/dist/index.cjs +1744 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2192 -0
- package/dist/index.d.ts +2192 -0
- package/dist/index.js +1507 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -5
- package/src/generated/accounts/ammConfig.ts +197 -0
- package/src/generated/accounts/index.ts +10 -0
- package/src/generated/accounts/pool.ts +274 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/pinaAmm.ts +66 -0
- package/src/generated/events/configCreated.ts +80 -0
- package/src/generated/events/configUpdated.ts +64 -0
- package/src/generated/events/feesCollected.ts +64 -0
- package/src/generated/events/index.ts +18 -0
- package/src/generated/events/liquidityChanged.ts +72 -0
- package/src/generated/events/logs.ts +732 -0
- package/src/generated/events/poolCreated.ts +80 -0
- 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/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 +20 -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/syncPool.ts +93 -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 +124 -0
- package/src/index.ts +11 -0
- package/CHANGELOG.md +0 -5
|
@@ -0,0 +1,142 @@
|
|
|
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, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, 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, type WritableSignerAccount } 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 CREATE_CONFIG_DISCRIMINATOR = 0;
|
|
15
|
+
|
|
16
|
+
export function getCreateConfigDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(CREATE_CONFIG_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type CreateConfigInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta<string> = string, TAccountUpgradeAuthority extends string | AccountMeta<string> = string, TAccountProgramData extends string | AccountMeta<string> = string, TAccountAmmConfig extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPayer extends string ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer> : TAccountPayer, TAccountUpgradeAuthority extends string ? ReadonlySignerAccount<TAccountUpgradeAuthority> & AccountSignerMeta<TAccountUpgradeAuthority> : TAccountUpgradeAuthority, TAccountProgramData extends string ? ReadonlyAccount<TAccountProgramData> : TAccountProgramData, TAccountAmmConfig extends string ? WritableAccount<TAccountAmmConfig> : TAccountAmmConfig, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type CreateConfigInstructionData = { discriminator: number;
|
|
22
|
+
/** Tier index; also the PDA seed. */
|
|
23
|
+
index: number;
|
|
24
|
+
/** Swap fee in parts per million. */
|
|
25
|
+
tradeFeeRate: number;
|
|
26
|
+
/** Protocol share of the trade fee in parts per million. */
|
|
27
|
+
protocolFeeRate: number;
|
|
28
|
+
/** Creator fee in parts per million. */
|
|
29
|
+
creatorFeeRate: number;
|
|
30
|
+
/** Signer that may update the tier and collect its protocol fees. */
|
|
31
|
+
authority: Address;
|
|
32
|
+
/**
|
|
33
|
+
* The only signer allowed to create pools in this tier, or the default
|
|
34
|
+
* address to let anyone create pools.
|
|
35
|
+
*/
|
|
36
|
+
poolCreatorAuthority: Address; };
|
|
37
|
+
|
|
38
|
+
export type CreateConfigInstructionDataArgs = {
|
|
39
|
+
/** Tier index; also the PDA seed. */
|
|
40
|
+
index: number;
|
|
41
|
+
/** Swap fee in parts per million. */
|
|
42
|
+
tradeFeeRate: number;
|
|
43
|
+
/** Protocol share of the trade fee in parts per million. */
|
|
44
|
+
protocolFeeRate: number;
|
|
45
|
+
/** Creator fee in parts per million. */
|
|
46
|
+
creatorFeeRate: number;
|
|
47
|
+
/** Signer that may update the tier and collect its protocol fees. */
|
|
48
|
+
authority: Address;
|
|
49
|
+
/**
|
|
50
|
+
* The only signer allowed to create pools in this tier, or the default
|
|
51
|
+
* address to let anyone create pools.
|
|
52
|
+
*/
|
|
53
|
+
poolCreatorAuthority: Address; };
|
|
54
|
+
|
|
55
|
+
export function getCreateConfigInstructionDataEncoder(): FixedSizeEncoder<CreateConfigInstructionDataArgs> {
|
|
56
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['index', getU16Encoder()], ['tradeFeeRate', getU32Encoder()], ['protocolFeeRate', getU32Encoder()], ['creatorFeeRate', getU32Encoder()], ['authority', getAddressEncoder()], ['poolCreatorAuthority', getAddressEncoder()]]), (value) => ({ ...value, discriminator: 0 }));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getCreateConfigInstructionDataDecoder(): FixedSizeDecoder<CreateConfigInstructionData> {
|
|
60
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(CREATE_CONFIG_DISCRIMINATOR, getU8Decoder())], ['index', getU16Decoder()], ['tradeFeeRate', getU32Decoder()], ['protocolFeeRate', getU32Decoder()], ['creatorFeeRate', getU32Decoder()], ['authority', getAddressDecoder()], ['poolCreatorAuthority', getAddressDecoder()]]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getCreateConfigInstructionDataCodec(): FixedSizeCodec<CreateConfigInstructionDataArgs, CreateConfigInstructionData> {
|
|
64
|
+
return combineCodec(getCreateConfigInstructionDataEncoder(), getCreateConfigInstructionDataDecoder());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type CreateConfigInput<TAccountPayer extends InstructionSignerInput = InstructionSignerInput, TAccountUpgradeAuthority extends InstructionSignerInput = InstructionSignerInput, TAccountProgramData extends InstructionAccountInput = InstructionAccountInput, TAccountAmmConfig extends InstructionAccountInput = InstructionAccountInput, TAccountSystemProgram extends InstructionAccountInput = InstructionAccountInput> = {
|
|
68
|
+
/** Pays the new tier's rent. */
|
|
69
|
+
payer: TAccountPayer;
|
|
70
|
+
/** The program's upgrade authority. */
|
|
71
|
+
upgradeAuthority: TAccountUpgradeAuthority;
|
|
72
|
+
/**
|
|
73
|
+
* The program's program-data account, which records its upgrade
|
|
74
|
+
* authority.
|
|
75
|
+
*/
|
|
76
|
+
programData: TAccountProgramData;
|
|
77
|
+
/** The tier PDA to create: `[b"amm_config", index]`. */
|
|
78
|
+
ammConfig: TAccountAmmConfig;
|
|
79
|
+
/** The system program. */
|
|
80
|
+
systemProgram?: TAccountSystemProgram;
|
|
81
|
+
index: CreateConfigInstructionDataArgs["index"];
|
|
82
|
+
tradeFeeRate: CreateConfigInstructionDataArgs["tradeFeeRate"];
|
|
83
|
+
protocolFeeRate: CreateConfigInstructionDataArgs["protocolFeeRate"];
|
|
84
|
+
creatorFeeRate: CreateConfigInstructionDataArgs["creatorFeeRate"];
|
|
85
|
+
authority: CreateConfigInstructionDataArgs["authority"];
|
|
86
|
+
poolCreatorAuthority: CreateConfigInstructionDataArgs["poolCreatorAuthority"];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function getCreateConfigInstruction<TAccountPayer extends InstructionSignerInput, TAccountUpgradeAuthority extends InstructionSignerInput, TAccountProgramData extends InstructionAccountInput, TAccountAmmConfig extends InstructionAccountInput, TAccountSystemProgram extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: CreateConfigInput<TAccountPayer, TAccountUpgradeAuthority, TAccountProgramData, TAccountAmmConfig, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): CreateConfigInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPayer, InstructionAccountInputAddress<TAccountPayer>>, ResolvedInstructionAccountMeta<TAccountUpgradeAuthority, InstructionAccountInputAddress<TAccountUpgradeAuthority>>, ResolvedInstructionAccountMeta<TAccountProgramData, InstructionAccountInputAddress<TAccountProgramData>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>, ResolvedInstructionAccountMeta<TAccountSystemProgram, InstructionAccountInputAddress<TAccountSystemProgram>>> {
|
|
90
|
+
// Program address.
|
|
91
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
92
|
+
|
|
93
|
+
// Account meta helper.
|
|
94
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
95
|
+
|
|
96
|
+
// Original accounts.
|
|
97
|
+
const originalAccounts = { payer: { value: input.payer ?? null, isSigner: true, isWritable: true }, upgradeAuthority: { value: input.upgradeAuthority ?? null, isSigner: true, isWritable: false }, programData: { value: input.programData ?? null, isSigner: false, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isSigner: false, isWritable: false } }
|
|
98
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// Original args.
|
|
102
|
+
const args = { ...input, };
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// Resolve default values.
|
|
106
|
+
if (!accounts.systemProgram.value) {
|
|
107
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return Object.freeze({ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("upgradeAuthority", accounts.upgradeAuthority), getAccountMeta("programData", accounts.programData), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("systemProgram", accounts.systemProgram)], data: getCreateConfigInstructionDataEncoder().encode(args as CreateConfigInstructionDataArgs), programAddress } as CreateConfigInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPayer, InstructionAccountInputAddress<TAccountPayer>>, ResolvedInstructionAccountMeta<TAccountUpgradeAuthority, InstructionAccountInputAddress<TAccountUpgradeAuthority>>, ResolvedInstructionAccountMeta<TAccountProgramData, InstructionAccountInputAddress<TAccountProgramData>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>, ResolvedInstructionAccountMeta<TAccountSystemProgram, InstructionAccountInputAddress<TAccountSystemProgram>>>);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type ParsedCreateConfigInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
114
|
+
accounts: {
|
|
115
|
+
/** Pays the new tier's rent. */
|
|
116
|
+
payer: TAccountMetas[0];
|
|
117
|
+
/** The program's upgrade authority. */
|
|
118
|
+
upgradeAuthority: TAccountMetas[1];
|
|
119
|
+
/**
|
|
120
|
+
* The program's program-data account, which records its upgrade
|
|
121
|
+
* authority.
|
|
122
|
+
*/
|
|
123
|
+
programData: TAccountMetas[2];
|
|
124
|
+
/** The tier PDA to create: `[b"amm_config", index]`. */
|
|
125
|
+
ammConfig: TAccountMetas[3];
|
|
126
|
+
/** The system program. */
|
|
127
|
+
systemProgram: TAccountMetas[4];
|
|
128
|
+
};
|
|
129
|
+
data: CreateConfigInstructionData; };
|
|
130
|
+
|
|
131
|
+
export function parseCreateConfigInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedCreateConfigInstruction<TProgram, TAccountMetas> {
|
|
132
|
+
if (instruction.accounts.length < 5) {
|
|
133
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5 });
|
|
134
|
+
}
|
|
135
|
+
let accountIndex = 0;
|
|
136
|
+
const getNextAccount = () => {
|
|
137
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
138
|
+
accountIndex += 1;
|
|
139
|
+
return accountMeta;
|
|
140
|
+
}
|
|
141
|
+
return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), upgradeAuthority: getNextAccount(), programData: getNextAccount(), ammConfig: getNextAccount(), systemProgram: getNextAccount() }, data: getCreateConfigInstructionDataDecoder().decode(instruction.data) };
|
|
142
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
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, getAddressDecoder, getAddressEncoder, 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, type WritableSignerAccount } from '@solana/kit';
|
|
11
|
+
import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type InstructionAccountInput, type InstructionAccountInputAddress, type InstructionSignerInput, type ResolvedInstructionAccount, type ResolvedInstructionAccountMeta } from '@solana/program-client-core';
|
|
12
|
+
import { findPoolPda } from '../pdas';
|
|
13
|
+
import { PINA_AMM_PROGRAM_ADDRESS } from '../programs';
|
|
14
|
+
|
|
15
|
+
export const CREATE_POOL_DISCRIMINATOR = 2;
|
|
16
|
+
|
|
17
|
+
export function getCreatePoolDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(CREATE_POOL_DISCRIMINATOR); }
|
|
18
|
+
|
|
19
|
+
export type CreatePoolInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta<string> = string, TAccountDepositor extends string | AccountMeta<string> = string, TAccountPoolCreatorAuthority extends string | AccountMeta<string> = string, TAccountAmmConfig extends string | AccountMeta<string> = string, TAccountMint0 extends string | AccountMeta<string> = string, TAccountMint1 extends string | AccountMeta<string> = string, TAccountPool extends string | AccountMeta<string> = string, TAccountLpMint extends string | AccountMeta<string> = string, TAccountVault0 extends string | AccountMeta<string> = string, TAccountVault1 extends string | AccountMeta<string> = string, TAccountDepositorToken0 extends string | AccountMeta<string> = string, TAccountDepositorToken1 extends string | AccountMeta<string> = string, TAccountLpOwner extends string | AccountMeta<string> = string, TAccountLpOwnerToken extends string | AccountMeta<string> = string, TAccountTokenProgram0 extends string | AccountMeta<string> = string, TAccountTokenProgram1 extends string | AccountMeta<string> = string, TAccountLpTokenProgram extends string | AccountMeta<string> = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountAssociatedTokenProgram extends string | AccountMeta<string> = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
20
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPayer extends string ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer> : TAccountPayer, TAccountDepositor extends string ? ReadonlySignerAccount<TAccountDepositor> & AccountSignerMeta<TAccountDepositor> : TAccountDepositor, TAccountPoolCreatorAuthority extends string ? ReadonlySignerAccount<TAccountPoolCreatorAuthority> & AccountSignerMeta<TAccountPoolCreatorAuthority> : TAccountPoolCreatorAuthority, TAccountAmmConfig extends string ? ReadonlyAccount<TAccountAmmConfig> : TAccountAmmConfig, TAccountMint0 extends string ? ReadonlyAccount<TAccountMint0> : TAccountMint0, TAccountMint1 extends string ? ReadonlyAccount<TAccountMint1> : TAccountMint1, TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool, TAccountLpMint extends string ? WritableAccount<TAccountLpMint> : TAccountLpMint, TAccountVault0 extends string ? WritableAccount<TAccountVault0> : TAccountVault0, TAccountVault1 extends string ? WritableAccount<TAccountVault1> : TAccountVault1, TAccountDepositorToken0 extends string ? WritableAccount<TAccountDepositorToken0> : TAccountDepositorToken0, TAccountDepositorToken1 extends string ? WritableAccount<TAccountDepositorToken1> : TAccountDepositorToken1, TAccountLpOwner extends string ? ReadonlyAccount<TAccountLpOwner> : TAccountLpOwner, TAccountLpOwnerToken extends string ? WritableAccount<TAccountLpOwnerToken> : TAccountLpOwnerToken, TAccountTokenProgram0 extends string ? ReadonlyAccount<TAccountTokenProgram0> : TAccountTokenProgram0, TAccountTokenProgram1 extends string ? ReadonlyAccount<TAccountTokenProgram1> : TAccountTokenProgram1, TAccountLpTokenProgram extends string ? ReadonlyAccount<TAccountLpTokenProgram> : TAccountLpTokenProgram, TAccountAssociatedTokenProgram extends string ? ReadonlyAccount<TAccountAssociatedTokenProgram> : TAccountAssociatedTokenProgram, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, ...TRemainingAccounts]>;
|
|
21
|
+
|
|
22
|
+
export type CreatePoolInstructionData = { discriminator: number;
|
|
23
|
+
/** Initial deposit of token 0. */
|
|
24
|
+
amount0: bigint;
|
|
25
|
+
/** Initial deposit of token 1. */
|
|
26
|
+
amount1: bigint;
|
|
27
|
+
/** Recipient of the pool's creator fees. */
|
|
28
|
+
creator: Address;
|
|
29
|
+
/** `CreatorFeeMode` wire value. */
|
|
30
|
+
creatorFeeMode: number; };
|
|
31
|
+
|
|
32
|
+
export type CreatePoolInstructionDataArgs = {
|
|
33
|
+
/** Initial deposit of token 0. */
|
|
34
|
+
amount0: number | bigint;
|
|
35
|
+
/** Initial deposit of token 1. */
|
|
36
|
+
amount1: number | bigint;
|
|
37
|
+
/** Recipient of the pool's creator fees. */
|
|
38
|
+
creator: Address;
|
|
39
|
+
/** `CreatorFeeMode` wire value. */
|
|
40
|
+
creatorFeeMode: number; };
|
|
41
|
+
|
|
42
|
+
export function getCreatePoolInstructionDataEncoder(): FixedSizeEncoder<CreatePoolInstructionDataArgs> {
|
|
43
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['amount0', getU64Encoder()], ['amount1', getU64Encoder()], ['creator', getAddressEncoder()], ['creatorFeeMode', getU8Encoder()]]), (value) => ({ ...value, discriminator: 2 }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getCreatePoolInstructionDataDecoder(): FixedSizeDecoder<CreatePoolInstructionData> {
|
|
47
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(CREATE_POOL_DISCRIMINATOR, getU8Decoder())], ['amount0', getU64Decoder()], ['amount1', getU64Decoder()], ['creator', getAddressDecoder()], ['creatorFeeMode', getU8Decoder()]]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getCreatePoolInstructionDataCodec(): FixedSizeCodec<CreatePoolInstructionDataArgs, CreatePoolInstructionData> {
|
|
51
|
+
return combineCodec(getCreatePoolInstructionDataEncoder(), getCreatePoolInstructionDataDecoder());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type CreatePoolAsyncInput<TAccountPayer extends InstructionSignerInput = InstructionSignerInput, TAccountDepositor extends InstructionSignerInput = InstructionSignerInput, TAccountPoolCreatorAuthority extends InstructionSignerInput = InstructionSignerInput, TAccountAmmConfig extends InstructionAccountInput = InstructionAccountInput, TAccountMint0 extends InstructionAccountInput = InstructionAccountInput, TAccountMint1 extends InstructionAccountInput = InstructionAccountInput, TAccountPool extends InstructionAccountInput = InstructionAccountInput, TAccountLpMint extends InstructionAccountInput = InstructionAccountInput, TAccountVault0 extends InstructionAccountInput = InstructionAccountInput, TAccountVault1 extends InstructionAccountInput = InstructionAccountInput, TAccountDepositorToken0 extends InstructionAccountInput = InstructionAccountInput, TAccountDepositorToken1 extends InstructionAccountInput = InstructionAccountInput, TAccountLpOwner extends InstructionAccountInput = InstructionAccountInput, TAccountLpOwnerToken extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput = InstructionAccountInput, TAccountLpTokenProgram extends InstructionAccountInput = InstructionAccountInput, TAccountAssociatedTokenProgram extends InstructionAccountInput = InstructionAccountInput, TAccountSystemProgram extends InstructionAccountInput = InstructionAccountInput> = {
|
|
55
|
+
/**
|
|
56
|
+
* Pays rent for the pool, its vaults, its LP mint, and the LP token
|
|
57
|
+
* account.
|
|
58
|
+
*/
|
|
59
|
+
payer: TAccountPayer;
|
|
60
|
+
/**
|
|
61
|
+
* Owner of the token accounts the initial deposit comes from. May be the
|
|
62
|
+
* same account as `payer`.
|
|
63
|
+
*/
|
|
64
|
+
depositor: TAccountDepositor;
|
|
65
|
+
/**
|
|
66
|
+
* Signer that authorizes pool creation. When the tier restricts pool
|
|
67
|
+
* creation this must be its pool-creator authority; otherwise any signer
|
|
68
|
+
* works, so pass the payer.
|
|
69
|
+
*/
|
|
70
|
+
poolCreatorAuthority: TAccountPoolCreatorAuthority;
|
|
71
|
+
/** The fee tier the pool is created under. */
|
|
72
|
+
ammConfig: TAccountAmmConfig;
|
|
73
|
+
/** Token 0 mint: the byte-wise smaller mint address. */
|
|
74
|
+
mint0: TAccountMint0;
|
|
75
|
+
/** Token 1 mint: the byte-wise larger mint address. */
|
|
76
|
+
mint1: TAccountMint1;
|
|
77
|
+
/** The pool PDA to create: `[b"pool", amm_config, mint_0, mint_1]`. */
|
|
78
|
+
pool?: TAccountPool;
|
|
79
|
+
/** The LP mint PDA to create: `[b"pool_lp_mint", pool]`. */
|
|
80
|
+
lpMint: TAccountLpMint;
|
|
81
|
+
/** The token 0 vault PDA to create: `[b"pool_vault", pool, mint_0]`. */
|
|
82
|
+
vault0: TAccountVault0;
|
|
83
|
+
/** The token 1 vault PDA to create: `[b"pool_vault", pool, mint_1]`. */
|
|
84
|
+
vault1: TAccountVault1;
|
|
85
|
+
/** The depositor's token 0 account. */
|
|
86
|
+
depositorToken0: TAccountDepositorToken0;
|
|
87
|
+
/** The depositor's token 1 account. */
|
|
88
|
+
depositorToken1: TAccountDepositorToken1;
|
|
89
|
+
/** Wallet that receives the initial LP. */
|
|
90
|
+
lpOwner: TAccountLpOwner;
|
|
91
|
+
/** `lp_owner`'s associated token account for the LP mint, created here. */
|
|
92
|
+
lpOwnerToken: TAccountLpOwnerToken;
|
|
93
|
+
/** Token program that owns `mint_0`. */
|
|
94
|
+
tokenProgram0: TAccountTokenProgram0;
|
|
95
|
+
/** Token program that owns `mint_1`. */
|
|
96
|
+
tokenProgram1: TAccountTokenProgram1;
|
|
97
|
+
/** SPL Token, which owns every LP mint. */
|
|
98
|
+
lpTokenProgram?: TAccountLpTokenProgram;
|
|
99
|
+
/** The associated token account program. */
|
|
100
|
+
associatedTokenProgram?: TAccountAssociatedTokenProgram;
|
|
101
|
+
/** The system program. */
|
|
102
|
+
systemProgram?: TAccountSystemProgram;
|
|
103
|
+
amount0: CreatePoolInstructionDataArgs["amount0"];
|
|
104
|
+
amount1: CreatePoolInstructionDataArgs["amount1"];
|
|
105
|
+
creator: CreatePoolInstructionDataArgs["creator"];
|
|
106
|
+
creatorFeeMode: CreatePoolInstructionDataArgs["creatorFeeMode"];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function getCreatePoolInstructionAsync<TAccountPayer extends InstructionSignerInput, TAccountDepositor extends InstructionSignerInput, TAccountPoolCreatorAuthority extends InstructionSignerInput, TAccountAmmConfig extends InstructionAccountInput, TAccountMint0 extends InstructionAccountInput, TAccountMint1 extends InstructionAccountInput, TAccountPool extends InstructionAccountInput, TAccountLpMint extends InstructionAccountInput, TAccountVault0 extends InstructionAccountInput, TAccountVault1 extends InstructionAccountInput, TAccountDepositorToken0 extends InstructionAccountInput, TAccountDepositorToken1 extends InstructionAccountInput, TAccountLpOwner extends InstructionAccountInput, TAccountLpOwnerToken extends InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput, TAccountLpTokenProgram extends InstructionAccountInput, TAccountAssociatedTokenProgram extends InstructionAccountInput, TAccountSystemProgram extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: CreatePoolAsyncInput<TAccountPayer, TAccountDepositor, TAccountPoolCreatorAuthority, TAccountAmmConfig, TAccountMint0, TAccountMint1, TAccountPool, TAccountLpMint, TAccountVault0, TAccountVault1, TAccountDepositorToken0, TAccountDepositorToken1, TAccountLpOwner, TAccountLpOwnerToken, TAccountTokenProgram0, TAccountTokenProgram1, TAccountLpTokenProgram, TAccountAssociatedTokenProgram, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): Promise<CreatePoolInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPayer, InstructionAccountInputAddress<TAccountPayer>>, ResolvedInstructionAccountMeta<TAccountDepositor, InstructionAccountInputAddress<TAccountDepositor>>, ResolvedInstructionAccountMeta<TAccountPoolCreatorAuthority, InstructionAccountInputAddress<TAccountPoolCreatorAuthority>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>, ResolvedInstructionAccountMeta<TAccountMint0, InstructionAccountInputAddress<TAccountMint0>>, ResolvedInstructionAccountMeta<TAccountMint1, InstructionAccountInputAddress<TAccountMint1>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountLpMint, InstructionAccountInputAddress<TAccountLpMint>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountDepositorToken0, InstructionAccountInputAddress<TAccountDepositorToken0>>, ResolvedInstructionAccountMeta<TAccountDepositorToken1, InstructionAccountInputAddress<TAccountDepositorToken1>>, ResolvedInstructionAccountMeta<TAccountLpOwner, InstructionAccountInputAddress<TAccountLpOwner>>, ResolvedInstructionAccountMeta<TAccountLpOwnerToken, InstructionAccountInputAddress<TAccountLpOwnerToken>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>, ResolvedInstructionAccountMeta<TAccountLpTokenProgram, InstructionAccountInputAddress<TAccountLpTokenProgram>>, ResolvedInstructionAccountMeta<TAccountAssociatedTokenProgram, InstructionAccountInputAddress<TAccountAssociatedTokenProgram>>, ResolvedInstructionAccountMeta<TAccountSystemProgram, InstructionAccountInputAddress<TAccountSystemProgram>>>> {
|
|
110
|
+
// Program address.
|
|
111
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
112
|
+
|
|
113
|
+
// Account meta helper.
|
|
114
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
115
|
+
|
|
116
|
+
// Original accounts.
|
|
117
|
+
const originalAccounts = { payer: { value: input.payer ?? null, isSigner: true, isWritable: true }, depositor: { value: input.depositor ?? null, isSigner: true, isWritable: false }, poolCreatorAuthority: { value: input.poolCreatorAuthority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: false }, mint0: { value: input.mint0 ?? null, isSigner: false, isWritable: false }, mint1: { value: input.mint1 ?? null, isSigner: false, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, lpMint: { value: input.lpMint ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, depositorToken0: { value: input.depositorToken0 ?? null, isSigner: false, isWritable: true }, depositorToken1: { value: input.depositorToken1 ?? null, isSigner: false, isWritable: true }, lpOwner: { value: input.lpOwner ?? null, isSigner: false, isWritable: false }, lpOwnerToken: { value: input.lpOwnerToken ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false }, lpTokenProgram: { value: input.lpTokenProgram ?? null, isSigner: false, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isSigner: false, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isSigner: false, isWritable: false } }
|
|
118
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
// Original args.
|
|
122
|
+
const args = { ...input, };
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// Resolve default values.
|
|
126
|
+
if (!accounts.pool.value) {
|
|
127
|
+
accounts.pool.value = await findPoolPda({ ammConfig: getAddressFromResolvedInstructionAccount("ammConfig", accounts.ammConfig.value), mint0: getAddressFromResolvedInstructionAccount("mint0", accounts.mint0.value), mint1: getAddressFromResolvedInstructionAccount("mint1", accounts.mint1.value) }, { programAddress });
|
|
128
|
+
}
|
|
129
|
+
if (!accounts.lpTokenProgram.value) {
|
|
130
|
+
accounts.lpTokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
|
|
131
|
+
}
|
|
132
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
133
|
+
accounts.associatedTokenProgram.value = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>;
|
|
134
|
+
}
|
|
135
|
+
if (!accounts.systemProgram.value) {
|
|
136
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Object.freeze({ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("depositor", accounts.depositor), getAccountMeta("poolCreatorAuthority", accounts.poolCreatorAuthority), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("mint0", accounts.mint0), getAccountMeta("mint1", accounts.mint1), getAccountMeta("pool", accounts.pool), getAccountMeta("lpMint", accounts.lpMint), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("depositorToken0", accounts.depositorToken0), getAccountMeta("depositorToken1", accounts.depositorToken1), getAccountMeta("lpOwner", accounts.lpOwner), getAccountMeta("lpOwnerToken", accounts.lpOwnerToken), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1), getAccountMeta("lpTokenProgram", accounts.lpTokenProgram), getAccountMeta("associatedTokenProgram", accounts.associatedTokenProgram), getAccountMeta("systemProgram", accounts.systemProgram)], data: getCreatePoolInstructionDataEncoder().encode(args as CreatePoolInstructionDataArgs), programAddress } as CreatePoolInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPayer, InstructionAccountInputAddress<TAccountPayer>>, ResolvedInstructionAccountMeta<TAccountDepositor, InstructionAccountInputAddress<TAccountDepositor>>, ResolvedInstructionAccountMeta<TAccountPoolCreatorAuthority, InstructionAccountInputAddress<TAccountPoolCreatorAuthority>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>, ResolvedInstructionAccountMeta<TAccountMint0, InstructionAccountInputAddress<TAccountMint0>>, ResolvedInstructionAccountMeta<TAccountMint1, InstructionAccountInputAddress<TAccountMint1>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountLpMint, InstructionAccountInputAddress<TAccountLpMint>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountDepositorToken0, InstructionAccountInputAddress<TAccountDepositorToken0>>, ResolvedInstructionAccountMeta<TAccountDepositorToken1, InstructionAccountInputAddress<TAccountDepositorToken1>>, ResolvedInstructionAccountMeta<TAccountLpOwner, InstructionAccountInputAddress<TAccountLpOwner>>, ResolvedInstructionAccountMeta<TAccountLpOwnerToken, InstructionAccountInputAddress<TAccountLpOwnerToken>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>, ResolvedInstructionAccountMeta<TAccountLpTokenProgram, InstructionAccountInputAddress<TAccountLpTokenProgram>>, ResolvedInstructionAccountMeta<TAccountAssociatedTokenProgram, InstructionAccountInputAddress<TAccountAssociatedTokenProgram>>, ResolvedInstructionAccountMeta<TAccountSystemProgram, InstructionAccountInputAddress<TAccountSystemProgram>>>);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type CreatePoolInput<TAccountPayer extends InstructionSignerInput = InstructionSignerInput, TAccountDepositor extends InstructionSignerInput = InstructionSignerInput, TAccountPoolCreatorAuthority extends InstructionSignerInput = InstructionSignerInput, TAccountAmmConfig extends InstructionAccountInput = InstructionAccountInput, TAccountMint0 extends InstructionAccountInput = InstructionAccountInput, TAccountMint1 extends InstructionAccountInput = InstructionAccountInput, TAccountPool extends InstructionAccountInput = InstructionAccountInput, TAccountLpMint extends InstructionAccountInput = InstructionAccountInput, TAccountVault0 extends InstructionAccountInput = InstructionAccountInput, TAccountVault1 extends InstructionAccountInput = InstructionAccountInput, TAccountDepositorToken0 extends InstructionAccountInput = InstructionAccountInput, TAccountDepositorToken1 extends InstructionAccountInput = InstructionAccountInput, TAccountLpOwner extends InstructionAccountInput = InstructionAccountInput, TAccountLpOwnerToken extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput = InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput = InstructionAccountInput, TAccountLpTokenProgram extends InstructionAccountInput = InstructionAccountInput, TAccountAssociatedTokenProgram extends InstructionAccountInput = InstructionAccountInput, TAccountSystemProgram extends InstructionAccountInput = InstructionAccountInput> = {
|
|
143
|
+
/**
|
|
144
|
+
* Pays rent for the pool, its vaults, its LP mint, and the LP token
|
|
145
|
+
* account.
|
|
146
|
+
*/
|
|
147
|
+
payer: TAccountPayer;
|
|
148
|
+
/**
|
|
149
|
+
* Owner of the token accounts the initial deposit comes from. May be the
|
|
150
|
+
* same account as `payer`.
|
|
151
|
+
*/
|
|
152
|
+
depositor: TAccountDepositor;
|
|
153
|
+
/**
|
|
154
|
+
* Signer that authorizes pool creation. When the tier restricts pool
|
|
155
|
+
* creation this must be its pool-creator authority; otherwise any signer
|
|
156
|
+
* works, so pass the payer.
|
|
157
|
+
*/
|
|
158
|
+
poolCreatorAuthority: TAccountPoolCreatorAuthority;
|
|
159
|
+
/** The fee tier the pool is created under. */
|
|
160
|
+
ammConfig: TAccountAmmConfig;
|
|
161
|
+
/** Token 0 mint: the byte-wise smaller mint address. */
|
|
162
|
+
mint0: TAccountMint0;
|
|
163
|
+
/** Token 1 mint: the byte-wise larger mint address. */
|
|
164
|
+
mint1: TAccountMint1;
|
|
165
|
+
/** The pool PDA to create: `[b"pool", amm_config, mint_0, mint_1]`. */
|
|
166
|
+
pool: TAccountPool;
|
|
167
|
+
/** The LP mint PDA to create: `[b"pool_lp_mint", pool]`. */
|
|
168
|
+
lpMint: TAccountLpMint;
|
|
169
|
+
/** The token 0 vault PDA to create: `[b"pool_vault", pool, mint_0]`. */
|
|
170
|
+
vault0: TAccountVault0;
|
|
171
|
+
/** The token 1 vault PDA to create: `[b"pool_vault", pool, mint_1]`. */
|
|
172
|
+
vault1: TAccountVault1;
|
|
173
|
+
/** The depositor's token 0 account. */
|
|
174
|
+
depositorToken0: TAccountDepositorToken0;
|
|
175
|
+
/** The depositor's token 1 account. */
|
|
176
|
+
depositorToken1: TAccountDepositorToken1;
|
|
177
|
+
/** Wallet that receives the initial LP. */
|
|
178
|
+
lpOwner: TAccountLpOwner;
|
|
179
|
+
/** `lp_owner`'s associated token account for the LP mint, created here. */
|
|
180
|
+
lpOwnerToken: TAccountLpOwnerToken;
|
|
181
|
+
/** Token program that owns `mint_0`. */
|
|
182
|
+
tokenProgram0: TAccountTokenProgram0;
|
|
183
|
+
/** Token program that owns `mint_1`. */
|
|
184
|
+
tokenProgram1: TAccountTokenProgram1;
|
|
185
|
+
/** SPL Token, which owns every LP mint. */
|
|
186
|
+
lpTokenProgram?: TAccountLpTokenProgram;
|
|
187
|
+
/** The associated token account program. */
|
|
188
|
+
associatedTokenProgram?: TAccountAssociatedTokenProgram;
|
|
189
|
+
/** The system program. */
|
|
190
|
+
systemProgram?: TAccountSystemProgram;
|
|
191
|
+
amount0: CreatePoolInstructionDataArgs["amount0"];
|
|
192
|
+
amount1: CreatePoolInstructionDataArgs["amount1"];
|
|
193
|
+
creator: CreatePoolInstructionDataArgs["creator"];
|
|
194
|
+
creatorFeeMode: CreatePoolInstructionDataArgs["creatorFeeMode"];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function getCreatePoolInstruction<TAccountPayer extends InstructionSignerInput, TAccountDepositor extends InstructionSignerInput, TAccountPoolCreatorAuthority extends InstructionSignerInput, TAccountAmmConfig extends InstructionAccountInput, TAccountMint0 extends InstructionAccountInput, TAccountMint1 extends InstructionAccountInput, TAccountPool extends InstructionAccountInput, TAccountLpMint extends InstructionAccountInput, TAccountVault0 extends InstructionAccountInput, TAccountVault1 extends InstructionAccountInput, TAccountDepositorToken0 extends InstructionAccountInput, TAccountDepositorToken1 extends InstructionAccountInput, TAccountLpOwner extends InstructionAccountInput, TAccountLpOwnerToken extends InstructionAccountInput, TAccountTokenProgram0 extends InstructionAccountInput, TAccountTokenProgram1 extends InstructionAccountInput, TAccountLpTokenProgram extends InstructionAccountInput, TAccountAssociatedTokenProgram extends InstructionAccountInput, TAccountSystemProgram extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: CreatePoolInput<TAccountPayer, TAccountDepositor, TAccountPoolCreatorAuthority, TAccountAmmConfig, TAccountMint0, TAccountMint1, TAccountPool, TAccountLpMint, TAccountVault0, TAccountVault1, TAccountDepositorToken0, TAccountDepositorToken1, TAccountLpOwner, TAccountLpOwnerToken, TAccountTokenProgram0, TAccountTokenProgram1, TAccountLpTokenProgram, TAccountAssociatedTokenProgram, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): CreatePoolInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPayer, InstructionAccountInputAddress<TAccountPayer>>, ResolvedInstructionAccountMeta<TAccountDepositor, InstructionAccountInputAddress<TAccountDepositor>>, ResolvedInstructionAccountMeta<TAccountPoolCreatorAuthority, InstructionAccountInputAddress<TAccountPoolCreatorAuthority>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>, ResolvedInstructionAccountMeta<TAccountMint0, InstructionAccountInputAddress<TAccountMint0>>, ResolvedInstructionAccountMeta<TAccountMint1, InstructionAccountInputAddress<TAccountMint1>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountLpMint, InstructionAccountInputAddress<TAccountLpMint>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountDepositorToken0, InstructionAccountInputAddress<TAccountDepositorToken0>>, ResolvedInstructionAccountMeta<TAccountDepositorToken1, InstructionAccountInputAddress<TAccountDepositorToken1>>, ResolvedInstructionAccountMeta<TAccountLpOwner, InstructionAccountInputAddress<TAccountLpOwner>>, ResolvedInstructionAccountMeta<TAccountLpOwnerToken, InstructionAccountInputAddress<TAccountLpOwnerToken>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>, ResolvedInstructionAccountMeta<TAccountLpTokenProgram, InstructionAccountInputAddress<TAccountLpTokenProgram>>, ResolvedInstructionAccountMeta<TAccountAssociatedTokenProgram, InstructionAccountInputAddress<TAccountAssociatedTokenProgram>>, ResolvedInstructionAccountMeta<TAccountSystemProgram, InstructionAccountInputAddress<TAccountSystemProgram>>> {
|
|
198
|
+
// Program address.
|
|
199
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
200
|
+
|
|
201
|
+
// Account meta helper.
|
|
202
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
203
|
+
|
|
204
|
+
// Original accounts.
|
|
205
|
+
const originalAccounts = { payer: { value: input.payer ?? null, isSigner: true, isWritable: true }, depositor: { value: input.depositor ?? null, isSigner: true, isWritable: false }, poolCreatorAuthority: { value: input.poolCreatorAuthority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: false }, mint0: { value: input.mint0 ?? null, isSigner: false, isWritable: false }, mint1: { value: input.mint1 ?? null, isSigner: false, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, lpMint: { value: input.lpMint ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, depositorToken0: { value: input.depositorToken0 ?? null, isSigner: false, isWritable: true }, depositorToken1: { value: input.depositorToken1 ?? null, isSigner: false, isWritable: true }, lpOwner: { value: input.lpOwner ?? null, isSigner: false, isWritable: false }, lpOwnerToken: { value: input.lpOwnerToken ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false }, lpTokenProgram: { value: input.lpTokenProgram ?? null, isSigner: false, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isSigner: false, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isSigner: false, isWritable: false } }
|
|
206
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
// Original args.
|
|
210
|
+
const args = { ...input, };
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
// Resolve default values.
|
|
214
|
+
if (!accounts.lpTokenProgram.value) {
|
|
215
|
+
accounts.lpTokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
|
|
216
|
+
}
|
|
217
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
218
|
+
accounts.associatedTokenProgram.value = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>;
|
|
219
|
+
}
|
|
220
|
+
if (!accounts.systemProgram.value) {
|
|
221
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return Object.freeze({ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("depositor", accounts.depositor), getAccountMeta("poolCreatorAuthority", accounts.poolCreatorAuthority), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("mint0", accounts.mint0), getAccountMeta("mint1", accounts.mint1), getAccountMeta("pool", accounts.pool), getAccountMeta("lpMint", accounts.lpMint), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("depositorToken0", accounts.depositorToken0), getAccountMeta("depositorToken1", accounts.depositorToken1), getAccountMeta("lpOwner", accounts.lpOwner), getAccountMeta("lpOwnerToken", accounts.lpOwnerToken), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1), getAccountMeta("lpTokenProgram", accounts.lpTokenProgram), getAccountMeta("associatedTokenProgram", accounts.associatedTokenProgram), getAccountMeta("systemProgram", accounts.systemProgram)], data: getCreatePoolInstructionDataEncoder().encode(args as CreatePoolInstructionDataArgs), programAddress } as CreatePoolInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountPayer, InstructionAccountInputAddress<TAccountPayer>>, ResolvedInstructionAccountMeta<TAccountDepositor, InstructionAccountInputAddress<TAccountDepositor>>, ResolvedInstructionAccountMeta<TAccountPoolCreatorAuthority, InstructionAccountInputAddress<TAccountPoolCreatorAuthority>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>, ResolvedInstructionAccountMeta<TAccountMint0, InstructionAccountInputAddress<TAccountMint0>>, ResolvedInstructionAccountMeta<TAccountMint1, InstructionAccountInputAddress<TAccountMint1>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountLpMint, InstructionAccountInputAddress<TAccountLpMint>>, ResolvedInstructionAccountMeta<TAccountVault0, InstructionAccountInputAddress<TAccountVault0>>, ResolvedInstructionAccountMeta<TAccountVault1, InstructionAccountInputAddress<TAccountVault1>>, ResolvedInstructionAccountMeta<TAccountDepositorToken0, InstructionAccountInputAddress<TAccountDepositorToken0>>, ResolvedInstructionAccountMeta<TAccountDepositorToken1, InstructionAccountInputAddress<TAccountDepositorToken1>>, ResolvedInstructionAccountMeta<TAccountLpOwner, InstructionAccountInputAddress<TAccountLpOwner>>, ResolvedInstructionAccountMeta<TAccountLpOwnerToken, InstructionAccountInputAddress<TAccountLpOwnerToken>>, ResolvedInstructionAccountMeta<TAccountTokenProgram0, InstructionAccountInputAddress<TAccountTokenProgram0>>, ResolvedInstructionAccountMeta<TAccountTokenProgram1, InstructionAccountInputAddress<TAccountTokenProgram1>>, ResolvedInstructionAccountMeta<TAccountLpTokenProgram, InstructionAccountInputAddress<TAccountLpTokenProgram>>, ResolvedInstructionAccountMeta<TAccountAssociatedTokenProgram, InstructionAccountInputAddress<TAccountAssociatedTokenProgram>>, ResolvedInstructionAccountMeta<TAccountSystemProgram, InstructionAccountInputAddress<TAccountSystemProgram>>>);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export type ParsedCreatePoolInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
228
|
+
accounts: {
|
|
229
|
+
/**
|
|
230
|
+
* Pays rent for the pool, its vaults, its LP mint, and the LP token
|
|
231
|
+
* account.
|
|
232
|
+
*/
|
|
233
|
+
payer: TAccountMetas[0];
|
|
234
|
+
/**
|
|
235
|
+
* Owner of the token accounts the initial deposit comes from. May be the
|
|
236
|
+
* same account as `payer`.
|
|
237
|
+
*/
|
|
238
|
+
depositor: TAccountMetas[1];
|
|
239
|
+
/**
|
|
240
|
+
* Signer that authorizes pool creation. When the tier restricts pool
|
|
241
|
+
* creation this must be its pool-creator authority; otherwise any signer
|
|
242
|
+
* works, so pass the payer.
|
|
243
|
+
*/
|
|
244
|
+
poolCreatorAuthority: TAccountMetas[2];
|
|
245
|
+
/** The fee tier the pool is created under. */
|
|
246
|
+
ammConfig: TAccountMetas[3];
|
|
247
|
+
/** Token 0 mint: the byte-wise smaller mint address. */
|
|
248
|
+
mint0: TAccountMetas[4];
|
|
249
|
+
/** Token 1 mint: the byte-wise larger mint address. */
|
|
250
|
+
mint1: TAccountMetas[5];
|
|
251
|
+
/** The pool PDA to create: `[b"pool", amm_config, mint_0, mint_1]`. */
|
|
252
|
+
pool: TAccountMetas[6];
|
|
253
|
+
/** The LP mint PDA to create: `[b"pool_lp_mint", pool]`. */
|
|
254
|
+
lpMint: TAccountMetas[7];
|
|
255
|
+
/** The token 0 vault PDA to create: `[b"pool_vault", pool, mint_0]`. */
|
|
256
|
+
vault0: TAccountMetas[8];
|
|
257
|
+
/** The token 1 vault PDA to create: `[b"pool_vault", pool, mint_1]`. */
|
|
258
|
+
vault1: TAccountMetas[9];
|
|
259
|
+
/** The depositor's token 0 account. */
|
|
260
|
+
depositorToken0: TAccountMetas[10];
|
|
261
|
+
/** The depositor's token 1 account. */
|
|
262
|
+
depositorToken1: TAccountMetas[11];
|
|
263
|
+
/** Wallet that receives the initial LP. */
|
|
264
|
+
lpOwner: TAccountMetas[12];
|
|
265
|
+
/** `lp_owner`'s associated token account for the LP mint, created here. */
|
|
266
|
+
lpOwnerToken: TAccountMetas[13];
|
|
267
|
+
/** Token program that owns `mint_0`. */
|
|
268
|
+
tokenProgram0: TAccountMetas[14];
|
|
269
|
+
/** Token program that owns `mint_1`. */
|
|
270
|
+
tokenProgram1: TAccountMetas[15];
|
|
271
|
+
/** SPL Token, which owns every LP mint. */
|
|
272
|
+
lpTokenProgram: TAccountMetas[16];
|
|
273
|
+
/** The associated token account program. */
|
|
274
|
+
associatedTokenProgram: TAccountMetas[17];
|
|
275
|
+
/** The system program. */
|
|
276
|
+
systemProgram: TAccountMetas[18];
|
|
277
|
+
};
|
|
278
|
+
data: CreatePoolInstructionData; };
|
|
279
|
+
|
|
280
|
+
export function parseCreatePoolInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedCreatePoolInstruction<TProgram, TAccountMetas> {
|
|
281
|
+
if (instruction.accounts.length < 19) {
|
|
282
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 19 });
|
|
283
|
+
}
|
|
284
|
+
let accountIndex = 0;
|
|
285
|
+
const getNextAccount = () => {
|
|
286
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
287
|
+
accountIndex += 1;
|
|
288
|
+
return accountMeta;
|
|
289
|
+
}
|
|
290
|
+
return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), depositor: getNextAccount(), poolCreatorAuthority: getNextAccount(), ammConfig: getNextAccount(), mint0: getNextAccount(), mint1: getNextAccount(), pool: getNextAccount(), lpMint: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), depositorToken0: getNextAccount(), depositorToken1: getNextAccount(), lpOwner: getNextAccount(), lpOwnerToken: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount(), lpTokenProgram: getNextAccount(), associatedTokenProgram: getNextAccount(), systemProgram: getNextAccount() }, data: getCreatePoolInstructionDataDecoder().decode(instruction.data) };
|
|
291
|
+
}
|
|
@@ -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 DEPOSIT_DISCRIMINATOR = 3;
|
|
15
|
+
|
|
16
|
+
export function getDepositDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(DEPOSIT_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type DepositInstruction<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 DepositInstructionData = { discriminator: number;
|
|
22
|
+
/** LP to mint. */
|
|
23
|
+
lpAmount: bigint;
|
|
24
|
+
/** Most token 0 the depositor will add. */
|
|
25
|
+
maximumAmount0: bigint;
|
|
26
|
+
/** Most token 1 the depositor will add. */
|
|
27
|
+
maximumAmount1: bigint; };
|
|
28
|
+
|
|
29
|
+
export type DepositInstructionDataArgs = {
|
|
30
|
+
/** LP to mint. */
|
|
31
|
+
lpAmount: number | bigint;
|
|
32
|
+
/** Most token 0 the depositor will add. */
|
|
33
|
+
maximumAmount0: number | bigint;
|
|
34
|
+
/** Most token 1 the depositor will add. */
|
|
35
|
+
maximumAmount1: number | bigint; };
|
|
36
|
+
|
|
37
|
+
export function getDepositInstructionDataEncoder(): FixedSizeEncoder<DepositInstructionDataArgs> {
|
|
38
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['lpAmount', getU64Encoder()], ['maximumAmount0', getU64Encoder()], ['maximumAmount1', getU64Encoder()]]), (value) => ({ ...value, discriminator: 3 }));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getDepositInstructionDataDecoder(): FixedSizeDecoder<DepositInstructionData> {
|
|
42
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(DEPOSIT_DISCRIMINATOR, getU8Decoder())], ['lpAmount', getU64Decoder()], ['maximumAmount0', getU64Decoder()], ['maximumAmount1', getU64Decoder()]]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getDepositInstructionDataCodec(): FixedSizeCodec<DepositInstructionDataArgs, DepositInstructionData> {
|
|
46
|
+
return combineCodec(getDepositInstructionDataEncoder(), getDepositInstructionDataDecoder());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type DepositInput<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: DepositInstructionDataArgs["lpAmount"];
|
|
73
|
+
maximumAmount0: DepositInstructionDataArgs["maximumAmount0"];
|
|
74
|
+
maximumAmount1: DepositInstructionDataArgs["maximumAmount1"];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getDepositInstruction<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: DepositInput<TAccountOwner, TAccountPool, TAccountVault0, TAccountVault1, TAccountLpMint, TAccountOwnerToken0, TAccountOwnerToken1, TAccountOwnerLpToken, TAccountTokenProgram0, TAccountTokenProgram1, TAccountLpTokenProgram>, config?: { programAddress?: TProgramAddress } ): DepositInstruction<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: getDepositInstructionDataEncoder().encode(args as DepositInstructionDataArgs), programAddress } as DepositInstruction<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 ParsedDepositInstruction<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: DepositInstructionData; };
|
|
127
|
+
|
|
128
|
+
export function parseDepositInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedDepositInstruction<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: getDepositInstructionDataDecoder().decode(instruction.data) };
|
|
139
|
+
}
|