@pina-rs/amm 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +27 -2
- package/dist/index.cjs +1257 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1752 -0
- package/dist/index.d.ts +1752 -0
- package/dist/index.js +1078 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -5
- package/src/generated/accounts/ammConfig.ts +197 -0
- package/src/generated/accounts/index.ts +10 -0
- package/src/generated/accounts/pool.ts +218 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/pinaAmm.ts +64 -0
- package/src/generated/events/feesCollected.ts +64 -0
- package/src/generated/events/index.ts +13 -0
- package/src/generated/events/liquidityChanged.ts +72 -0
- package/src/generated/events/logs.ts +372 -0
- package/src/generated/events/poolCreated.ts +80 -0
- package/src/generated/events/swapped.ts +100 -0
- package/src/generated/index.ts +14 -0
- package/src/generated/instructions/collectCreatorFees.ts +119 -0
- package/src/generated/instructions/collectProtocolFees.ts +123 -0
- package/src/generated/instructions/createConfig.ts +142 -0
- package/src/generated/instructions/createPool.ts +291 -0
- package/src/generated/instructions/deposit.ts +139 -0
- package/src/generated/instructions/index.ts +19 -0
- package/src/generated/instructions/migrate.ts +155 -0
- package/src/generated/instructions/setPoolCreator.ts +90 -0
- package/src/generated/instructions/swapExactIn.ts +119 -0
- package/src/generated/instructions/swapExactOut.ts +119 -0
- package/src/generated/instructions/updateConfig.ts +105 -0
- package/src/generated/instructions/withdraw.ts +139 -0
- package/src/generated/pdas/ammConfig.ts +18 -0
- package/src/generated/pdas/index.ts +12 -0
- package/src/generated/pdas/pool.ts +20 -0
- package/src/generated/pdas/poolLpMint.ts +18 -0
- package/src/generated/pdas/poolVault.ts +19 -0
- package/src/generated/pinaPodCodecs.ts +232 -0
- package/src/generated/programs/index.ts +9 -0
- package/src/generated/programs/pinaAmm.ts +115 -0
- package/src/index.ts +11 -0
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
* The framework-owned `Migrate` instruction: it runs the program's on-demand
|
|
9
|
+
* account migrations on their own, so the payer authorizes exactly the
|
|
10
|
+
* migration cost and the business instruction that follows sees current
|
|
11
|
+
* data. The intended flow around any instruction that failed with a
|
|
12
|
+
* migration version mismatch is catch -> migrate -> retry.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
type AccountMeta,
|
|
17
|
+
type AccountSignerMeta,
|
|
18
|
+
type Address,
|
|
19
|
+
type Instruction,
|
|
20
|
+
type InstructionWithAccounts,
|
|
21
|
+
type InstructionWithData,
|
|
22
|
+
type ReadonlyAccount,
|
|
23
|
+
type ReadonlyUint8Array,
|
|
24
|
+
type TransactionSigner,
|
|
25
|
+
type WritableAccount,
|
|
26
|
+
type WritableSignerAccount,
|
|
27
|
+
} from "@solana/kit";
|
|
28
|
+
import {
|
|
29
|
+
getAccountMetaFactory,
|
|
30
|
+
type ResolvedInstructionAccount,
|
|
31
|
+
} from "@solana/program-client-core";
|
|
32
|
+
import { PINA_AMM_PROGRAM_ADDRESS } from "../programs";
|
|
33
|
+
|
|
34
|
+
/** Discriminator reserved by Pina for the framework `Migrate` instruction. */
|
|
35
|
+
export const MIGRATE_DISCRIMINATOR = 255;
|
|
36
|
+
|
|
37
|
+
export function getMigrateDiscriminatorBytes(): ReadonlyUint8Array {
|
|
38
|
+
return new Uint8Array([255]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type MigrateInstruction<
|
|
42
|
+
TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS,
|
|
43
|
+
TAccountPayer extends string | AccountMeta<string> = string,
|
|
44
|
+
TAccountSystemProgram extends string | AccountMeta<string> = string,
|
|
45
|
+
TAccountAmmConfig extends string | AccountMeta<string> = string,
|
|
46
|
+
TAccountPool extends string | AccountMeta<string> = string,
|
|
47
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
48
|
+
> =
|
|
49
|
+
& Instruction<TProgram>
|
|
50
|
+
& InstructionWithData<ReadonlyUint8Array>
|
|
51
|
+
& InstructionWithAccounts<
|
|
52
|
+
[
|
|
53
|
+
TAccountPayer extends string ?
|
|
54
|
+
& WritableSignerAccount<TAccountPayer>
|
|
55
|
+
& AccountSignerMeta<TAccountPayer>
|
|
56
|
+
: TAccountPayer,
|
|
57
|
+
TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram>
|
|
58
|
+
: TAccountSystemProgram,
|
|
59
|
+
TAccountAmmConfig extends string ? WritableAccount<TAccountAmmConfig>
|
|
60
|
+
: TAccountAmmConfig,
|
|
61
|
+
TAccountPool extends string ? WritableAccount<TAccountPool>
|
|
62
|
+
: TAccountPool,
|
|
63
|
+
...TRemainingAccounts,
|
|
64
|
+
]
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export type MigrateInput<
|
|
68
|
+
TAccountPayer extends string = string,
|
|
69
|
+
TAccountSystemProgram extends string = string,
|
|
70
|
+
TAccountAmmConfig extends string = string,
|
|
71
|
+
TAccountPool extends string = string,
|
|
72
|
+
> = {
|
|
73
|
+
payer?: TransactionSigner<TAccountPayer>;
|
|
74
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
75
|
+
ammConfig?: Address<TAccountAmmConfig>;
|
|
76
|
+
pool?: Address<TAccountPool>;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Composes the reserved `Migrate` instruction.
|
|
81
|
+
*
|
|
82
|
+
* Every migratable account is optional: omitted slots are filled with the
|
|
83
|
+
* program-address placeholder and trailing omitted slots are dropped, so a
|
|
84
|
+
* client sends only the accounts it needs to migrate. The `payer` funds rent
|
|
85
|
+
* deficits and must be a writable signer; omit it when no migration needs
|
|
86
|
+
* funding. `systemProgram` defaults to the system program, the only account
|
|
87
|
+
* the program accepts in that slot. The program caps the whole
|
|
88
|
+
* instruction's rent transfers at a program-chosen lamport budget.
|
|
89
|
+
*/
|
|
90
|
+
export function getMigrateInstruction<
|
|
91
|
+
TAccountPayer extends string = string,
|
|
92
|
+
TAccountSystemProgram extends string = string,
|
|
93
|
+
TAccountAmmConfig extends string = string,
|
|
94
|
+
TAccountPool extends string = string,
|
|
95
|
+
TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS,
|
|
96
|
+
>(
|
|
97
|
+
input: MigrateInput<
|
|
98
|
+
TAccountPayer,
|
|
99
|
+
TAccountSystemProgram,
|
|
100
|
+
TAccountAmmConfig,
|
|
101
|
+
TAccountPool
|
|
102
|
+
>,
|
|
103
|
+
config?: { programAddress?: TProgramAddress },
|
|
104
|
+
): MigrateInstruction<
|
|
105
|
+
TProgramAddress,
|
|
106
|
+
TAccountPayer,
|
|
107
|
+
TAccountSystemProgram,
|
|
108
|
+
TAccountAmmConfig,
|
|
109
|
+
TAccountPool
|
|
110
|
+
> {
|
|
111
|
+
// Program address.
|
|
112
|
+
const programAddress = config?.programAddress ??
|
|
113
|
+
PINA_AMM_PROGRAM_ADDRESS;
|
|
114
|
+
|
|
115
|
+
// Original accounts.
|
|
116
|
+
const originalAccounts = {
|
|
117
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
118
|
+
systemProgram: { value: input.systemProgram ?? ("11111111111111111111111111111111" as Address<"11111111111111111111111111111111">), isWritable: false },
|
|
119
|
+
ammConfig: { value: input.ammConfig ?? null, isWritable: true },
|
|
120
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
121
|
+
};
|
|
122
|
+
const accounts = originalAccounts as Record<
|
|
123
|
+
keyof typeof originalAccounts,
|
|
124
|
+
ResolvedInstructionAccount
|
|
125
|
+
>;
|
|
126
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
127
|
+
|
|
128
|
+
// Migratable slots after the last provided account may be truncated: the
|
|
129
|
+
// program treats a missing trailing slot exactly like the program-address
|
|
130
|
+
// placeholder. The payer and system program slots are always sent.
|
|
131
|
+
const provided: readonly unknown[] = [input.ammConfig, input.pool];
|
|
132
|
+
let lastProvided = -1;
|
|
133
|
+
for (let index = 0; index < provided.length; index += 1) {
|
|
134
|
+
if (provided[index] != null) {
|
|
135
|
+
lastProvided = index;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return Object.freeze({
|
|
140
|
+
accounts: [
|
|
141
|
+
getAccountMeta("payer", accounts.payer),
|
|
142
|
+
getAccountMeta("systemProgram", accounts.systemProgram),
|
|
143
|
+
getAccountMeta("ammConfig", accounts.ammConfig),
|
|
144
|
+
getAccountMeta("pool", accounts.pool),
|
|
145
|
+
].slice(0, 2 + lastProvided + 1),
|
|
146
|
+
data: getMigrateDiscriminatorBytes(),
|
|
147
|
+
programAddress,
|
|
148
|
+
} as MigrateInstruction<
|
|
149
|
+
TProgramAddress,
|
|
150
|
+
TAccountPayer,
|
|
151
|
+
TAccountSystemProgram,
|
|
152
|
+
TAccountAmmConfig,
|
|
153
|
+
TAccountPool
|
|
154
|
+
>);
|
|
155
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
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, 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 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 SET_POOL_CREATOR_DISCRIMINATOR = 9;
|
|
15
|
+
|
|
16
|
+
export function getSetPoolCreatorDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SET_POOL_CREATOR_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type SetPoolCreatorInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountCreator extends string | AccountMeta<string> = string, TAccountPool extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountCreator extends string ? ReadonlySignerAccount<TAccountCreator> & AccountSignerMeta<TAccountCreator> : TAccountCreator, TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type SetPoolCreatorInstructionData = { discriminator: number;
|
|
22
|
+
/** New recipient of the pool's creator fees. */
|
|
23
|
+
newCreator: Address; };
|
|
24
|
+
|
|
25
|
+
export type SetPoolCreatorInstructionDataArgs = {
|
|
26
|
+
/** New recipient of the pool's creator fees. */
|
|
27
|
+
newCreator: Address; };
|
|
28
|
+
|
|
29
|
+
export function getSetPoolCreatorInstructionDataEncoder(): FixedSizeEncoder<SetPoolCreatorInstructionDataArgs> {
|
|
30
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['newCreator', getAddressEncoder()]]), (value) => ({ ...value, discriminator: 9 }));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getSetPoolCreatorInstructionDataDecoder(): FixedSizeDecoder<SetPoolCreatorInstructionData> {
|
|
34
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(SET_POOL_CREATOR_DISCRIMINATOR, getU8Decoder())], ['newCreator', getAddressDecoder()]]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getSetPoolCreatorInstructionDataCodec(): FixedSizeCodec<SetPoolCreatorInstructionDataArgs, SetPoolCreatorInstructionData> {
|
|
38
|
+
return combineCodec(getSetPoolCreatorInstructionDataEncoder(), getSetPoolCreatorInstructionDataDecoder());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type SetPoolCreatorInput<TAccountCreator extends InstructionSignerInput = InstructionSignerInput, TAccountPool extends InstructionAccountInput = InstructionAccountInput> = {
|
|
42
|
+
/** The pool's current creator. */
|
|
43
|
+
creator: TAccountCreator;
|
|
44
|
+
/** The pool. */
|
|
45
|
+
pool: TAccountPool;
|
|
46
|
+
newCreator: SetPoolCreatorInstructionDataArgs["newCreator"];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getSetPoolCreatorInstruction<TAccountCreator extends InstructionSignerInput, TAccountPool extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: SetPoolCreatorInput<TAccountCreator, TAccountPool>, config?: { programAddress?: TProgramAddress } ): SetPoolCreatorInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountCreator, InstructionAccountInputAddress<TAccountCreator>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>> {
|
|
50
|
+
// Program address.
|
|
51
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
52
|
+
|
|
53
|
+
// Account meta helper.
|
|
54
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
55
|
+
|
|
56
|
+
// Original accounts.
|
|
57
|
+
const originalAccounts = { creator: { value: input.creator ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true } }
|
|
58
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// Original args.
|
|
62
|
+
const args = { ...input, };
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
return Object.freeze({ accounts: [getAccountMeta("creator", accounts.creator), getAccountMeta("pool", accounts.pool)], data: getSetPoolCreatorInstructionDataEncoder().encode(args as SetPoolCreatorInstructionDataArgs), programAddress } as SetPoolCreatorInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountCreator, InstructionAccountInputAddress<TAccountCreator>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>>);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type ParsedSetPoolCreatorInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
71
|
+
accounts: {
|
|
72
|
+
/** The pool's current creator. */
|
|
73
|
+
creator: TAccountMetas[0];
|
|
74
|
+
/** The pool. */
|
|
75
|
+
pool: TAccountMetas[1];
|
|
76
|
+
};
|
|
77
|
+
data: SetPoolCreatorInstructionData; };
|
|
78
|
+
|
|
79
|
+
export function parseSetPoolCreatorInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetPoolCreatorInstruction<TProgram, TAccountMetas> {
|
|
80
|
+
if (instruction.accounts.length < 2) {
|
|
81
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2 });
|
|
82
|
+
}
|
|
83
|
+
let accountIndex = 0;
|
|
84
|
+
const getNextAccount = () => {
|
|
85
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
86
|
+
accountIndex += 1;
|
|
87
|
+
return accountMeta;
|
|
88
|
+
}
|
|
89
|
+
return { programAddress: instruction.programAddress, accounts: { creator: getNextAccount(), pool: getNextAccount() }, data: getSetPoolCreatorInstructionDataDecoder().decode(instruction.data) };
|
|
90
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 SWAP_EXACT_IN_DISCRIMINATOR = 5;
|
|
15
|
+
|
|
16
|
+
export function getSwapExactInDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SWAP_EXACT_IN_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type SwapExactInInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountTrader extends string | AccountMeta<string> = string, TAccountPool extends string | AccountMeta<string> = string, TAccountInputToken extends string | AccountMeta<string> = string, TAccountOutputToken extends string | AccountMeta<string> = string, TAccountInputVault extends string | AccountMeta<string> = string, TAccountOutputVault extends string | AccountMeta<string> = string, TAccountInputTokenProgram extends string | AccountMeta<string> = string, TAccountOutputTokenProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountTrader extends string ? ReadonlySignerAccount<TAccountTrader> & AccountSignerMeta<TAccountTrader> : TAccountTrader, TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool, TAccountInputToken extends string ? WritableAccount<TAccountInputToken> : TAccountInputToken, TAccountOutputToken extends string ? WritableAccount<TAccountOutputToken> : TAccountOutputToken, TAccountInputVault extends string ? WritableAccount<TAccountInputVault> : TAccountInputVault, TAccountOutputVault extends string ? WritableAccount<TAccountOutputVault> : TAccountOutputVault, TAccountInputTokenProgram extends string ? ReadonlyAccount<TAccountInputTokenProgram> : TAccountInputTokenProgram, TAccountOutputTokenProgram extends string ? ReadonlyAccount<TAccountOutputTokenProgram> : TAccountOutputTokenProgram, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type SwapExactInInstructionData = { discriminator: number;
|
|
22
|
+
/** Exact input the trader sells. */
|
|
23
|
+
amountIn: bigint;
|
|
24
|
+
/** Least output the trader will accept. */
|
|
25
|
+
minimumAmountOut: bigint; };
|
|
26
|
+
|
|
27
|
+
export type SwapExactInInstructionDataArgs = {
|
|
28
|
+
/** Exact input the trader sells. */
|
|
29
|
+
amountIn: number | bigint;
|
|
30
|
+
/** Least output the trader will accept. */
|
|
31
|
+
minimumAmountOut: number | bigint; };
|
|
32
|
+
|
|
33
|
+
export function getSwapExactInInstructionDataEncoder(): FixedSizeEncoder<SwapExactInInstructionDataArgs> {
|
|
34
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['amountIn', getU64Encoder()], ['minimumAmountOut', getU64Encoder()]]), (value) => ({ ...value, discriminator: 5 }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getSwapExactInInstructionDataDecoder(): FixedSizeDecoder<SwapExactInInstructionData> {
|
|
38
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(SWAP_EXACT_IN_DISCRIMINATOR, getU8Decoder())], ['amountIn', getU64Decoder()], ['minimumAmountOut', getU64Decoder()]]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getSwapExactInInstructionDataCodec(): FixedSizeCodec<SwapExactInInstructionDataArgs, SwapExactInInstructionData> {
|
|
42
|
+
return combineCodec(getSwapExactInInstructionDataEncoder(), getSwapExactInInstructionDataDecoder());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type SwapExactInInput<TAccountTrader extends InstructionSignerInput = InstructionSignerInput, TAccountPool extends InstructionAccountInput = InstructionAccountInput, TAccountInputToken extends InstructionAccountInput = InstructionAccountInput, TAccountOutputToken extends InstructionAccountInput = InstructionAccountInput, TAccountInputVault extends InstructionAccountInput = InstructionAccountInput, TAccountOutputVault extends InstructionAccountInput = InstructionAccountInput, TAccountInputTokenProgram extends InstructionAccountInput = InstructionAccountInput, TAccountOutputTokenProgram extends InstructionAccountInput = InstructionAccountInput> = {
|
|
46
|
+
/** The trader, who owns `input_token`. */
|
|
47
|
+
trader: TAccountTrader;
|
|
48
|
+
/** The pool to trade against. */
|
|
49
|
+
pool: TAccountPool;
|
|
50
|
+
/** The trader's account for the token being sold. */
|
|
51
|
+
inputToken: TAccountInputToken;
|
|
52
|
+
/** The account that receives the token being bought. */
|
|
53
|
+
outputToken: TAccountOutputToken;
|
|
54
|
+
/** The pool's vault for the token being sold. */
|
|
55
|
+
inputVault: TAccountInputVault;
|
|
56
|
+
/** The pool's vault for the token being bought. */
|
|
57
|
+
outputVault: TAccountOutputVault;
|
|
58
|
+
/** Token program that owns the sold token. */
|
|
59
|
+
inputTokenProgram: TAccountInputTokenProgram;
|
|
60
|
+
/** Token program that owns the bought token. */
|
|
61
|
+
outputTokenProgram: TAccountOutputTokenProgram;
|
|
62
|
+
amountIn: SwapExactInInstructionDataArgs["amountIn"];
|
|
63
|
+
minimumAmountOut: SwapExactInInstructionDataArgs["minimumAmountOut"];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getSwapExactInInstruction<TAccountTrader extends InstructionSignerInput, TAccountPool extends InstructionAccountInput, TAccountInputToken extends InstructionAccountInput, TAccountOutputToken extends InstructionAccountInput, TAccountInputVault extends InstructionAccountInput, TAccountOutputVault extends InstructionAccountInput, TAccountInputTokenProgram extends InstructionAccountInput, TAccountOutputTokenProgram extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: SwapExactInInput<TAccountTrader, TAccountPool, TAccountInputToken, TAccountOutputToken, TAccountInputVault, TAccountOutputVault, TAccountInputTokenProgram, TAccountOutputTokenProgram>, config?: { programAddress?: TProgramAddress } ): SwapExactInInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountTrader, InstructionAccountInputAddress<TAccountTrader>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountInputToken, InstructionAccountInputAddress<TAccountInputToken>>, ResolvedInstructionAccountMeta<TAccountOutputToken, InstructionAccountInputAddress<TAccountOutputToken>>, ResolvedInstructionAccountMeta<TAccountInputVault, InstructionAccountInputAddress<TAccountInputVault>>, ResolvedInstructionAccountMeta<TAccountOutputVault, InstructionAccountInputAddress<TAccountOutputVault>>, ResolvedInstructionAccountMeta<TAccountInputTokenProgram, InstructionAccountInputAddress<TAccountInputTokenProgram>>, ResolvedInstructionAccountMeta<TAccountOutputTokenProgram, InstructionAccountInputAddress<TAccountOutputTokenProgram>>> {
|
|
67
|
+
// Program address.
|
|
68
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
69
|
+
|
|
70
|
+
// Account meta helper.
|
|
71
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
72
|
+
|
|
73
|
+
// Original accounts.
|
|
74
|
+
const originalAccounts = { trader: { value: input.trader ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, inputToken: { value: input.inputToken ?? null, isSigner: false, isWritable: true }, outputToken: { value: input.outputToken ?? null, isSigner: false, isWritable: true }, inputVault: { value: input.inputVault ?? null, isSigner: false, isWritable: true }, outputVault: { value: input.outputVault ?? null, isSigner: false, isWritable: true }, inputTokenProgram: { value: input.inputTokenProgram ?? null, isSigner: false, isWritable: false }, outputTokenProgram: { value: input.outputTokenProgram ?? null, isSigner: false, isWritable: false } }
|
|
75
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// Original args.
|
|
79
|
+
const args = { ...input, };
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
return Object.freeze({ accounts: [getAccountMeta("trader", accounts.trader), getAccountMeta("pool", accounts.pool), getAccountMeta("inputToken", accounts.inputToken), getAccountMeta("outputToken", accounts.outputToken), getAccountMeta("inputVault", accounts.inputVault), getAccountMeta("outputVault", accounts.outputVault), getAccountMeta("inputTokenProgram", accounts.inputTokenProgram), getAccountMeta("outputTokenProgram", accounts.outputTokenProgram)], data: getSwapExactInInstructionDataEncoder().encode(args as SwapExactInInstructionDataArgs), programAddress } as SwapExactInInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountTrader, InstructionAccountInputAddress<TAccountTrader>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountInputToken, InstructionAccountInputAddress<TAccountInputToken>>, ResolvedInstructionAccountMeta<TAccountOutputToken, InstructionAccountInputAddress<TAccountOutputToken>>, ResolvedInstructionAccountMeta<TAccountInputVault, InstructionAccountInputAddress<TAccountInputVault>>, ResolvedInstructionAccountMeta<TAccountOutputVault, InstructionAccountInputAddress<TAccountOutputVault>>, ResolvedInstructionAccountMeta<TAccountInputTokenProgram, InstructionAccountInputAddress<TAccountInputTokenProgram>>, ResolvedInstructionAccountMeta<TAccountOutputTokenProgram, InstructionAccountInputAddress<TAccountOutputTokenProgram>>>);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type ParsedSwapExactInInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
88
|
+
accounts: {
|
|
89
|
+
/** The trader, who owns `input_token`. */
|
|
90
|
+
trader: TAccountMetas[0];
|
|
91
|
+
/** The pool to trade against. */
|
|
92
|
+
pool: TAccountMetas[1];
|
|
93
|
+
/** The trader's account for the token being sold. */
|
|
94
|
+
inputToken: TAccountMetas[2];
|
|
95
|
+
/** The account that receives the token being bought. */
|
|
96
|
+
outputToken: TAccountMetas[3];
|
|
97
|
+
/** The pool's vault for the token being sold. */
|
|
98
|
+
inputVault: TAccountMetas[4];
|
|
99
|
+
/** The pool's vault for the token being bought. */
|
|
100
|
+
outputVault: TAccountMetas[5];
|
|
101
|
+
/** Token program that owns the sold token. */
|
|
102
|
+
inputTokenProgram: TAccountMetas[6];
|
|
103
|
+
/** Token program that owns the bought token. */
|
|
104
|
+
outputTokenProgram: TAccountMetas[7];
|
|
105
|
+
};
|
|
106
|
+
data: SwapExactInInstructionData; };
|
|
107
|
+
|
|
108
|
+
export function parseSwapExactInInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSwapExactInInstruction<TProgram, TAccountMetas> {
|
|
109
|
+
if (instruction.accounts.length < 8) {
|
|
110
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8 });
|
|
111
|
+
}
|
|
112
|
+
let accountIndex = 0;
|
|
113
|
+
const getNextAccount = () => {
|
|
114
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
115
|
+
accountIndex += 1;
|
|
116
|
+
return accountMeta;
|
|
117
|
+
}
|
|
118
|
+
return { programAddress: instruction.programAddress, accounts: { trader: getNextAccount(), pool: getNextAccount(), inputToken: getNextAccount(), outputToken: getNextAccount(), inputVault: getNextAccount(), outputVault: getNextAccount(), inputTokenProgram: getNextAccount(), outputTokenProgram: getNextAccount() }, data: getSwapExactInInstructionDataDecoder().decode(instruction.data) };
|
|
119
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 SWAP_EXACT_OUT_DISCRIMINATOR = 6;
|
|
15
|
+
|
|
16
|
+
export function getSwapExactOutDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SWAP_EXACT_OUT_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type SwapExactOutInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountTrader extends string | AccountMeta<string> = string, TAccountPool extends string | AccountMeta<string> = string, TAccountInputToken extends string | AccountMeta<string> = string, TAccountOutputToken extends string | AccountMeta<string> = string, TAccountInputVault extends string | AccountMeta<string> = string, TAccountOutputVault extends string | AccountMeta<string> = string, TAccountInputTokenProgram extends string | AccountMeta<string> = string, TAccountOutputTokenProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountTrader extends string ? ReadonlySignerAccount<TAccountTrader> & AccountSignerMeta<TAccountTrader> : TAccountTrader, TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool, TAccountInputToken extends string ? WritableAccount<TAccountInputToken> : TAccountInputToken, TAccountOutputToken extends string ? WritableAccount<TAccountOutputToken> : TAccountOutputToken, TAccountInputVault extends string ? WritableAccount<TAccountInputVault> : TAccountInputVault, TAccountOutputVault extends string ? WritableAccount<TAccountOutputVault> : TAccountOutputVault, TAccountInputTokenProgram extends string ? ReadonlyAccount<TAccountInputTokenProgram> : TAccountInputTokenProgram, TAccountOutputTokenProgram extends string ? ReadonlyAccount<TAccountOutputTokenProgram> : TAccountOutputTokenProgram, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type SwapExactOutInstructionData = { discriminator: number;
|
|
22
|
+
/** Exact output the trader buys. */
|
|
23
|
+
amountOut: bigint;
|
|
24
|
+
/** Most input the trader will pay. */
|
|
25
|
+
maximumAmountIn: bigint; };
|
|
26
|
+
|
|
27
|
+
export type SwapExactOutInstructionDataArgs = {
|
|
28
|
+
/** Exact output the trader buys. */
|
|
29
|
+
amountOut: number | bigint;
|
|
30
|
+
/** Most input the trader will pay. */
|
|
31
|
+
maximumAmountIn: number | bigint; };
|
|
32
|
+
|
|
33
|
+
export function getSwapExactOutInstructionDataEncoder(): FixedSizeEncoder<SwapExactOutInstructionDataArgs> {
|
|
34
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['amountOut', getU64Encoder()], ['maximumAmountIn', getU64Encoder()]]), (value) => ({ ...value, discriminator: 6 }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getSwapExactOutInstructionDataDecoder(): FixedSizeDecoder<SwapExactOutInstructionData> {
|
|
38
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(SWAP_EXACT_OUT_DISCRIMINATOR, getU8Decoder())], ['amountOut', getU64Decoder()], ['maximumAmountIn', getU64Decoder()]]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getSwapExactOutInstructionDataCodec(): FixedSizeCodec<SwapExactOutInstructionDataArgs, SwapExactOutInstructionData> {
|
|
42
|
+
return combineCodec(getSwapExactOutInstructionDataEncoder(), getSwapExactOutInstructionDataDecoder());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type SwapExactOutInput<TAccountTrader extends InstructionSignerInput = InstructionSignerInput, TAccountPool extends InstructionAccountInput = InstructionAccountInput, TAccountInputToken extends InstructionAccountInput = InstructionAccountInput, TAccountOutputToken extends InstructionAccountInput = InstructionAccountInput, TAccountInputVault extends InstructionAccountInput = InstructionAccountInput, TAccountOutputVault extends InstructionAccountInput = InstructionAccountInput, TAccountInputTokenProgram extends InstructionAccountInput = InstructionAccountInput, TAccountOutputTokenProgram extends InstructionAccountInput = InstructionAccountInput> = {
|
|
46
|
+
/** The trader, who owns `input_token`. */
|
|
47
|
+
trader: TAccountTrader;
|
|
48
|
+
/** The pool to trade against. */
|
|
49
|
+
pool: TAccountPool;
|
|
50
|
+
/** The trader's account for the token being sold. */
|
|
51
|
+
inputToken: TAccountInputToken;
|
|
52
|
+
/** The account that receives the token being bought. */
|
|
53
|
+
outputToken: TAccountOutputToken;
|
|
54
|
+
/** The pool's vault for the token being sold. */
|
|
55
|
+
inputVault: TAccountInputVault;
|
|
56
|
+
/** The pool's vault for the token being bought. */
|
|
57
|
+
outputVault: TAccountOutputVault;
|
|
58
|
+
/** Token program that owns the sold token. */
|
|
59
|
+
inputTokenProgram: TAccountInputTokenProgram;
|
|
60
|
+
/** Token program that owns the bought token. */
|
|
61
|
+
outputTokenProgram: TAccountOutputTokenProgram;
|
|
62
|
+
amountOut: SwapExactOutInstructionDataArgs["amountOut"];
|
|
63
|
+
maximumAmountIn: SwapExactOutInstructionDataArgs["maximumAmountIn"];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getSwapExactOutInstruction<TAccountTrader extends InstructionSignerInput, TAccountPool extends InstructionAccountInput, TAccountInputToken extends InstructionAccountInput, TAccountOutputToken extends InstructionAccountInput, TAccountInputVault extends InstructionAccountInput, TAccountOutputVault extends InstructionAccountInput, TAccountInputTokenProgram extends InstructionAccountInput, TAccountOutputTokenProgram extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: SwapExactOutInput<TAccountTrader, TAccountPool, TAccountInputToken, TAccountOutputToken, TAccountInputVault, TAccountOutputVault, TAccountInputTokenProgram, TAccountOutputTokenProgram>, config?: { programAddress?: TProgramAddress } ): SwapExactOutInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountTrader, InstructionAccountInputAddress<TAccountTrader>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountInputToken, InstructionAccountInputAddress<TAccountInputToken>>, ResolvedInstructionAccountMeta<TAccountOutputToken, InstructionAccountInputAddress<TAccountOutputToken>>, ResolvedInstructionAccountMeta<TAccountInputVault, InstructionAccountInputAddress<TAccountInputVault>>, ResolvedInstructionAccountMeta<TAccountOutputVault, InstructionAccountInputAddress<TAccountOutputVault>>, ResolvedInstructionAccountMeta<TAccountInputTokenProgram, InstructionAccountInputAddress<TAccountInputTokenProgram>>, ResolvedInstructionAccountMeta<TAccountOutputTokenProgram, InstructionAccountInputAddress<TAccountOutputTokenProgram>>> {
|
|
67
|
+
// Program address.
|
|
68
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
69
|
+
|
|
70
|
+
// Account meta helper.
|
|
71
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
72
|
+
|
|
73
|
+
// Original accounts.
|
|
74
|
+
const originalAccounts = { trader: { value: input.trader ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, inputToken: { value: input.inputToken ?? null, isSigner: false, isWritable: true }, outputToken: { value: input.outputToken ?? null, isSigner: false, isWritable: true }, inputVault: { value: input.inputVault ?? null, isSigner: false, isWritable: true }, outputVault: { value: input.outputVault ?? null, isSigner: false, isWritable: true }, inputTokenProgram: { value: input.inputTokenProgram ?? null, isSigner: false, isWritable: false }, outputTokenProgram: { value: input.outputTokenProgram ?? null, isSigner: false, isWritable: false } }
|
|
75
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// Original args.
|
|
79
|
+
const args = { ...input, };
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
return Object.freeze({ accounts: [getAccountMeta("trader", accounts.trader), getAccountMeta("pool", accounts.pool), getAccountMeta("inputToken", accounts.inputToken), getAccountMeta("outputToken", accounts.outputToken), getAccountMeta("inputVault", accounts.inputVault), getAccountMeta("outputVault", accounts.outputVault), getAccountMeta("inputTokenProgram", accounts.inputTokenProgram), getAccountMeta("outputTokenProgram", accounts.outputTokenProgram)], data: getSwapExactOutInstructionDataEncoder().encode(args as SwapExactOutInstructionDataArgs), programAddress } as SwapExactOutInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountTrader, InstructionAccountInputAddress<TAccountTrader>>, ResolvedInstructionAccountMeta<TAccountPool, InstructionAccountInputAddress<TAccountPool>>, ResolvedInstructionAccountMeta<TAccountInputToken, InstructionAccountInputAddress<TAccountInputToken>>, ResolvedInstructionAccountMeta<TAccountOutputToken, InstructionAccountInputAddress<TAccountOutputToken>>, ResolvedInstructionAccountMeta<TAccountInputVault, InstructionAccountInputAddress<TAccountInputVault>>, ResolvedInstructionAccountMeta<TAccountOutputVault, InstructionAccountInputAddress<TAccountOutputVault>>, ResolvedInstructionAccountMeta<TAccountInputTokenProgram, InstructionAccountInputAddress<TAccountInputTokenProgram>>, ResolvedInstructionAccountMeta<TAccountOutputTokenProgram, InstructionAccountInputAddress<TAccountOutputTokenProgram>>>);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type ParsedSwapExactOutInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
88
|
+
accounts: {
|
|
89
|
+
/** The trader, who owns `input_token`. */
|
|
90
|
+
trader: TAccountMetas[0];
|
|
91
|
+
/** The pool to trade against. */
|
|
92
|
+
pool: TAccountMetas[1];
|
|
93
|
+
/** The trader's account for the token being sold. */
|
|
94
|
+
inputToken: TAccountMetas[2];
|
|
95
|
+
/** The account that receives the token being bought. */
|
|
96
|
+
outputToken: TAccountMetas[3];
|
|
97
|
+
/** The pool's vault for the token being sold. */
|
|
98
|
+
inputVault: TAccountMetas[4];
|
|
99
|
+
/** The pool's vault for the token being bought. */
|
|
100
|
+
outputVault: TAccountMetas[5];
|
|
101
|
+
/** Token program that owns the sold token. */
|
|
102
|
+
inputTokenProgram: TAccountMetas[6];
|
|
103
|
+
/** Token program that owns the bought token. */
|
|
104
|
+
outputTokenProgram: TAccountMetas[7];
|
|
105
|
+
};
|
|
106
|
+
data: SwapExactOutInstructionData; };
|
|
107
|
+
|
|
108
|
+
export function parseSwapExactOutInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSwapExactOutInstruction<TProgram, TAccountMetas> {
|
|
109
|
+
if (instruction.accounts.length < 8) {
|
|
110
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8 });
|
|
111
|
+
}
|
|
112
|
+
let accountIndex = 0;
|
|
113
|
+
const getNextAccount = () => {
|
|
114
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
115
|
+
accountIndex += 1;
|
|
116
|
+
return accountMeta;
|
|
117
|
+
}
|
|
118
|
+
return { programAddress: instruction.programAddress, accounts: { trader: getNextAccount(), pool: getNextAccount(), inputToken: getNextAccount(), outputToken: getNextAccount(), inputVault: getNextAccount(), outputVault: getNextAccount(), inputTokenProgram: getNextAccount(), outputTokenProgram: getNextAccount() }, data: getSwapExactOutInstructionDataDecoder().decode(instruction.data) };
|
|
119
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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, 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 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 UPDATE_CONFIG_DISCRIMINATOR = 1;
|
|
15
|
+
|
|
16
|
+
export function getUpdateConfigDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(UPDATE_CONFIG_DISCRIMINATOR); }
|
|
17
|
+
|
|
18
|
+
export type UpdateConfigInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta<string> = string, TAccountAmmConfig extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
19
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority> : TAccountAuthority, TAccountAmmConfig extends string ? WritableAccount<TAccountAmmConfig> : TAccountAmmConfig, ...TRemainingAccounts]>;
|
|
20
|
+
|
|
21
|
+
export type UpdateConfigInstructionData = { discriminator: number;
|
|
22
|
+
/** New tier authority. Pass the current authority to keep it. */
|
|
23
|
+
newAuthority: Address;
|
|
24
|
+
/** Swap fee future pools snapshot, in parts per million. */
|
|
25
|
+
tradeFeeRate: number;
|
|
26
|
+
/** Protocol share future pools snapshot, in parts per million. */
|
|
27
|
+
protocolFeeRate: number;
|
|
28
|
+
/** Creator fee future pools snapshot, in parts per million. */
|
|
29
|
+
creatorFeeRate: number; };
|
|
30
|
+
|
|
31
|
+
export type UpdateConfigInstructionDataArgs = {
|
|
32
|
+
/** New tier authority. Pass the current authority to keep it. */
|
|
33
|
+
newAuthority: Address;
|
|
34
|
+
/** Swap fee future pools snapshot, in parts per million. */
|
|
35
|
+
tradeFeeRate: number;
|
|
36
|
+
/** Protocol share future pools snapshot, in parts per million. */
|
|
37
|
+
protocolFeeRate: number;
|
|
38
|
+
/** Creator fee future pools snapshot, in parts per million. */
|
|
39
|
+
creatorFeeRate: number; };
|
|
40
|
+
|
|
41
|
+
export function getUpdateConfigInstructionDataEncoder(): FixedSizeEncoder<UpdateConfigInstructionDataArgs> {
|
|
42
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['newAuthority', getAddressEncoder()], ['tradeFeeRate', getU32Encoder()], ['protocolFeeRate', getU32Encoder()], ['creatorFeeRate', getU32Encoder()]]), (value) => ({ ...value, discriminator: 1 }));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getUpdateConfigInstructionDataDecoder(): FixedSizeDecoder<UpdateConfigInstructionData> {
|
|
46
|
+
return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(UPDATE_CONFIG_DISCRIMINATOR, getU8Decoder())], ['newAuthority', getAddressDecoder()], ['tradeFeeRate', getU32Decoder()], ['protocolFeeRate', getU32Decoder()], ['creatorFeeRate', getU32Decoder()]]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getUpdateConfigInstructionDataCodec(): FixedSizeCodec<UpdateConfigInstructionDataArgs, UpdateConfigInstructionData> {
|
|
50
|
+
return combineCodec(getUpdateConfigInstructionDataEncoder(), getUpdateConfigInstructionDataDecoder());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type UpdateConfigInput<TAccountAuthority extends InstructionSignerInput = InstructionSignerInput, TAccountAmmConfig extends InstructionAccountInput = InstructionAccountInput> = {
|
|
54
|
+
/** The tier's current authority. */
|
|
55
|
+
authority: TAccountAuthority;
|
|
56
|
+
/** The tier to update. */
|
|
57
|
+
ammConfig: TAccountAmmConfig;
|
|
58
|
+
newAuthority: UpdateConfigInstructionDataArgs["newAuthority"];
|
|
59
|
+
tradeFeeRate: UpdateConfigInstructionDataArgs["tradeFeeRate"];
|
|
60
|
+
protocolFeeRate: UpdateConfigInstructionDataArgs["protocolFeeRate"];
|
|
61
|
+
creatorFeeRate: UpdateConfigInstructionDataArgs["creatorFeeRate"];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getUpdateConfigInstruction<TAccountAuthority extends InstructionSignerInput, TAccountAmmConfig extends InstructionAccountInput, TProgramAddress extends Address = typeof PINA_AMM_PROGRAM_ADDRESS>(input: UpdateConfigInput<TAccountAuthority, TAccountAmmConfig>, config?: { programAddress?: TProgramAddress } ): UpdateConfigInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountAuthority, InstructionAccountInputAddress<TAccountAuthority>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>> {
|
|
65
|
+
// Program address.
|
|
66
|
+
const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
|
|
67
|
+
|
|
68
|
+
// Account meta helper.
|
|
69
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
70
|
+
|
|
71
|
+
// Original accounts.
|
|
72
|
+
const originalAccounts = { authority: { value: input.authority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: true } }
|
|
73
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// Original args.
|
|
77
|
+
const args = { ...input, };
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
return Object.freeze({ accounts: [getAccountMeta("authority", accounts.authority), getAccountMeta("ammConfig", accounts.ammConfig)], data: getUpdateConfigInstructionDataEncoder().encode(args as UpdateConfigInstructionDataArgs), programAddress } as UpdateConfigInstruction<TProgramAddress, ResolvedInstructionAccountMeta<TAccountAuthority, InstructionAccountInputAddress<TAccountAuthority>>, ResolvedInstructionAccountMeta<TAccountAmmConfig, InstructionAccountInputAddress<TAccountAmmConfig>>>);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type ParsedUpdateConfigInstruction<TProgram extends string = typeof PINA_AMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
86
|
+
accounts: {
|
|
87
|
+
/** The tier's current authority. */
|
|
88
|
+
authority: TAccountMetas[0];
|
|
89
|
+
/** The tier to update. */
|
|
90
|
+
ammConfig: TAccountMetas[1];
|
|
91
|
+
};
|
|
92
|
+
data: UpdateConfigInstructionData; };
|
|
93
|
+
|
|
94
|
+
export function parseUpdateConfigInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateConfigInstruction<TProgram, TAccountMetas> {
|
|
95
|
+
if (instruction.accounts.length < 2) {
|
|
96
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2 });
|
|
97
|
+
}
|
|
98
|
+
let accountIndex = 0;
|
|
99
|
+
const getNextAccount = () => {
|
|
100
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
101
|
+
accountIndex += 1;
|
|
102
|
+
return accountMeta;
|
|
103
|
+
}
|
|
104
|
+
return { programAddress: instruction.programAddress, accounts: { authority: getNextAccount(), ammConfig: getNextAccount() }, data: getUpdateConfigInstructionDataDecoder().decode(instruction.data) };
|
|
105
|
+
}
|