@send-fun/sdk 1.0.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 +21 -0
- package/README.md +32 -0
- package/dist/index.cjs +12808 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4406 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4405 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +12749 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +72 -0
- package/src/constants.ts +38 -0
- package/src/dex/generated/accounts/globalConfig.ts +189 -0
- package/src/dex/generated/accounts/index.ts +12 -0
- package/src/dex/generated/accounts/pool.ts +244 -0
- package/src/dex/generated/accounts/rewardAccrual.ts +191 -0
- package/src/dex/generated/accounts/sendDex.accounts.ts +47 -0
- package/src/dex/generated/errors/index.ts +9 -0
- package/src/dex/generated/errors/sendDex.ts +161 -0
- package/src/dex/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/dex/generated/events/creatorClaimEvent.ts +119 -0
- package/src/dex/generated/events/depositQuoteEvent.ts +115 -0
- package/src/dex/generated/events/index.ts +16 -0
- package/src/dex/generated/events/poolCreateEvent.ts +128 -0
- package/src/dex/generated/events/protocolClaimEvent.ts +111 -0
- package/src/dex/generated/events/sendDex.events.ts +184 -0
- package/src/dex/generated/events/tokenCreateEvent.ts +143 -0
- package/src/dex/generated/events/tradeEvent.ts +143 -0
- package/src/dex/generated/index.ts +16 -0
- package/src/dex/generated/instructions/buyExactIn.ts +815 -0
- package/src/dex/generated/instructions/buyExactOut.ts +815 -0
- package/src/dex/generated/instructions/claimCreatorFees.ts +648 -0
- package/src/dex/generated/instructions/claimProtocolFees.ts +640 -0
- package/src/dex/generated/instructions/index.ts +15 -0
- package/src/dex/generated/instructions/sellExactIn.ts +815 -0
- package/src/dex/generated/instructions/sellExactOut.ts +815 -0
- package/src/dex/generated/instructions/sendDex.instructions.ts +173 -0
- package/src/dex/generated/pdas/eventAuthority.ts +20 -0
- package/src/dex/generated/pdas/globalConfig.ts +20 -0
- package/src/dex/generated/pdas/index.ts +14 -0
- package/src/dex/generated/pdas/lpMint.ts +36 -0
- package/src/dex/generated/pdas/pool.ts +34 -0
- package/src/dex/generated/pdas/rewardAccrual.ts +37 -0
- package/src/dex/generated/pdas/wsolRewardAccrual.ts +20 -0
- package/src/dex/generated/plugins/index.ts +9 -0
- package/src/dex/generated/plugins/sendDex.ts +282 -0
- package/src/dex/generated/programs/index.ts +9 -0
- package/src/dex/generated/programs/sendDex.ts +12 -0
- package/src/dex/generated/types/index.ts +10 -0
- package/src/dex/generated/types/poolStatus.ts +38 -0
- package/src/dex/generated/types/tradeDirection.ts +38 -0
- package/src/dex/index.ts +8 -0
- package/src/dex/trade.ts +215 -0
- package/src/index.ts +8 -0
- package/src/launchpad/create.ts +116 -0
- package/src/launchpad/generated/accounts/bondingCurve.ts +273 -0
- package/src/launchpad/generated/accounts/globalConfig.ts +211 -0
- package/src/launchpad/generated/accounts/index.ts +12 -0
- package/src/launchpad/generated/accounts/rewardAccrual.ts +191 -0
- package/src/launchpad/generated/accounts/sendLaunchpad.accounts.ts +50 -0
- package/src/launchpad/generated/errors/index.ts +9 -0
- package/src/launchpad/generated/errors/sendLaunchpad.ts +175 -0
- package/src/launchpad/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/launchpad/generated/events/completeEvent.ts +120 -0
- package/src/launchpad/generated/events/creatorClaimEvent.ts +122 -0
- package/src/launchpad/generated/events/index.ts +17 -0
- package/src/launchpad/generated/events/migrateEvent.ts +121 -0
- package/src/launchpad/generated/events/protocolClaimEvent.ts +114 -0
- package/src/launchpad/generated/events/recycleEvent.ts +113 -0
- package/src/launchpad/generated/events/sendLaunchpad.events.ts +207 -0
- package/src/launchpad/generated/events/tokenCreateEvent.ts +156 -0
- package/src/launchpad/generated/events/tradeEvent.ts +148 -0
- package/src/launchpad/generated/index.ts +16 -0
- package/src/launchpad/generated/instructions/buyExactIn.ts +818 -0
- package/src/launchpad/generated/instructions/buyExactOut.ts +818 -0
- package/src/launchpad/generated/instructions/claimCreatorFees.ts +651 -0
- package/src/launchpad/generated/instructions/claimProtocolFees.ts +640 -0
- package/src/launchpad/generated/instructions/createToken.ts +1150 -0
- package/src/launchpad/generated/instructions/index.ts +17 -0
- package/src/launchpad/generated/instructions/migrate.ts +840 -0
- package/src/launchpad/generated/instructions/sellExactIn.ts +818 -0
- package/src/launchpad/generated/instructions/sellExactOut.ts +818 -0
- package/src/launchpad/generated/instructions/sendLaunchpad.instructions.ts +210 -0
- package/src/launchpad/generated/pdas/bondingCurve.ts +39 -0
- package/src/launchpad/generated/pdas/eventAuthority.ts +20 -0
- package/src/launchpad/generated/pdas/globalConfig.ts +20 -0
- package/src/launchpad/generated/pdas/index.ts +14 -0
- package/src/launchpad/generated/pdas/migrationAuthority.ts +20 -0
- package/src/launchpad/generated/pdas/rewardAccrual.ts +37 -0
- package/src/launchpad/generated/pdas/wsolRewardAccrual.ts +20 -0
- package/src/launchpad/generated/plugins/index.ts +9 -0
- package/src/launchpad/generated/plugins/sendLaunchpad.ts +315 -0
- package/src/launchpad/generated/programs/index.ts +9 -0
- package/src/launchpad/generated/programs/sendLaunchpad.ts +12 -0
- package/src/launchpad/generated/types/bondingCurveStatus.ts +43 -0
- package/src/launchpad/generated/types/index.ts +10 -0
- package/src/launchpad/generated/types/tradeDirection.ts +38 -0
- package/src/launchpad/index.ts +10 -0
- package/src/launchpad/migrate.ts +54 -0
- package/src/launchpad/trade.ts +247 -0
- package/src/math/amm.ts +511 -0
- package/src/math/fee-decay.ts +49 -0
- package/src/math/fees.ts +75 -0
- package/src/math/index.ts +3 -0
- package/src/math/internal.ts +16 -0
- package/src/nexus/fee-helpers.ts +49 -0
- package/src/nexus/generated/accounts/altRegistry.ts +177 -0
- package/src/nexus/generated/accounts/creatorFeeConfig.ts +200 -0
- package/src/nexus/generated/accounts/feePreset.ts +196 -0
- package/src/nexus/generated/accounts/globalConfig.ts +188 -0
- package/src/nexus/generated/accounts/index.ts +19 -0
- package/src/nexus/generated/accounts/partnerConfig.ts +209 -0
- package/src/nexus/generated/accounts/partnerMetadata.ts +216 -0
- package/src/nexus/generated/accounts/rewardState.ts +209 -0
- package/src/nexus/generated/accounts/sendNexus.accounts.ts +85 -0
- package/src/nexus/generated/accounts/stakingConfig.ts +197 -0
- package/src/nexus/generated/accounts/userRewardDebt.ts +221 -0
- package/src/nexus/generated/accounts/userStakePosition.ts +218 -0
- package/src/nexus/generated/constants/index.ts +9 -0
- package/src/nexus/generated/constants/sendNexus.ts +13 -0
- package/src/nexus/generated/errors/index.ts +9 -0
- package/src/nexus/generated/errors/sendNexus.ts +229 -0
- package/src/nexus/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/nexus/generated/events/claimEvent.ts +106 -0
- package/src/nexus/generated/events/index.ts +13 -0
- package/src/nexus/generated/events/sendNexus.events.ts +121 -0
- package/src/nexus/generated/events/stakeEvent.ts +106 -0
- package/src/nexus/generated/events/unstakeEvent.ts +106 -0
- package/src/nexus/generated/index.ts +17 -0
- package/src/nexus/generated/instructions/claim.ts +740 -0
- package/src/nexus/generated/instructions/createUserRewardDebt.ts +498 -0
- package/src/nexus/generated/instructions/index.ts +14 -0
- package/src/nexus/generated/instructions/sendNexus.instructions.ts +146 -0
- package/src/nexus/generated/instructions/settle.ts +517 -0
- package/src/nexus/generated/instructions/stake.ts +615 -0
- package/src/nexus/generated/instructions/unstake.ts +593 -0
- package/src/nexus/generated/pdas/altRegistry.ts +20 -0
- package/src/nexus/generated/pdas/creatorFeeConfig.ts +39 -0
- package/src/nexus/generated/pdas/defaultFeePreset.ts +37 -0
- package/src/nexus/generated/pdas/defaultPartner.ts +40 -0
- package/src/nexus/generated/pdas/defaultPartnerMetadata.ts +42 -0
- package/src/nexus/generated/pdas/eventAuthority.ts +20 -0
- package/src/nexus/generated/pdas/feePreset.ts +39 -0
- package/src/nexus/generated/pdas/globalConfig.ts +20 -0
- package/src/nexus/generated/pdas/index.ts +22 -0
- package/src/nexus/generated/pdas/partnerConfig.ts +36 -0
- package/src/nexus/generated/pdas/partnerMetadata.ts +38 -0
- package/src/nexus/generated/pdas/rewardState.ts +36 -0
- package/src/nexus/generated/pdas/stakingConfig.ts +20 -0
- package/src/nexus/generated/pdas/userRewardDebt.ts +41 -0
- package/src/nexus/generated/pdas/userStakePosition.ts +39 -0
- package/src/nexus/generated/plugins/index.ts +9 -0
- package/src/nexus/generated/plugins/sendNexus.ts +494 -0
- package/src/nexus/generated/programs/index.ts +9 -0
- package/src/nexus/generated/programs/sendNexus.ts +12 -0
- package/src/nexus/generated/types/authPlatformEntry.ts +52 -0
- package/src/nexus/generated/types/callerType.ts +38 -0
- package/src/nexus/generated/types/dexFees.ts +64 -0
- package/src/nexus/generated/types/feeConfig.ts +73 -0
- package/src/nexus/generated/types/index.ts +13 -0
- package/src/nexus/generated/types/launchpadFees.ts +63 -0
- package/src/nexus/index.ts +9 -0
- package/src/nexus/staking.ts +581 -0
- package/src/platform.ts +19 -0
- package/src/transfer-fee.ts +216 -0
- package/src/utils/chunk.ts +21 -0
- package/src/utils/creator-hash.ts +57 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/mint-info.ts +102 -0
- package/src/utils/partner.ts +5 -0
- package/src/utils/pda.ts +24 -0
|
@@ -0,0 +1,815 @@
|
|
|
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 {
|
|
10
|
+
address,
|
|
11
|
+
assertIsInstructionForProgram,
|
|
12
|
+
combineCodec,
|
|
13
|
+
containsBytes,
|
|
14
|
+
fixDecoderSize,
|
|
15
|
+
fixEncoderSize,
|
|
16
|
+
getAddressEncoder,
|
|
17
|
+
getBytesDecoder,
|
|
18
|
+
getBytesEncoder,
|
|
19
|
+
getProgramDerivedAddress,
|
|
20
|
+
getStructDecoder,
|
|
21
|
+
getStructEncoder,
|
|
22
|
+
getU64Decoder,
|
|
23
|
+
getU64Encoder,
|
|
24
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
25
|
+
SolanaError,
|
|
26
|
+
transformEncoder,
|
|
27
|
+
type AccountMeta,
|
|
28
|
+
type AccountSignerMeta,
|
|
29
|
+
type Address,
|
|
30
|
+
type FixedSizeCodec,
|
|
31
|
+
type FixedSizeDecoder,
|
|
32
|
+
type FixedSizeEncoder,
|
|
33
|
+
type Instruction,
|
|
34
|
+
type InstructionWithAccounts,
|
|
35
|
+
type InstructionWithData,
|
|
36
|
+
type ReadonlyAccount,
|
|
37
|
+
type ReadonlySignerAccount,
|
|
38
|
+
type ReadonlyUint8Array,
|
|
39
|
+
type TransactionSigner,
|
|
40
|
+
type WritableAccount,
|
|
41
|
+
type WritableSignerAccount,
|
|
42
|
+
} from '@solana/kit';
|
|
43
|
+
import {
|
|
44
|
+
getAccountMetaFactory,
|
|
45
|
+
getAddressFromResolvedInstructionAccount,
|
|
46
|
+
getNonNullResolvedInstructionInput,
|
|
47
|
+
type ResolvedInstructionAccount,
|
|
48
|
+
} from '@solana/program-client-core';
|
|
49
|
+
import { EVENT_AUTHORITY_PDA_ADDRESS, findPoolPda } from '../pdas/index.js';
|
|
50
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
51
|
+
|
|
52
|
+
export const SELL_EXACT_IN_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
53
|
+
149, 39, 222, 155, 211, 124, 152, 26,
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
export function getSellExactInDiscriminatorBytes(): ReadonlyUint8Array {
|
|
57
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
58
|
+
SELL_EXACT_IN_DISCRIMINATOR,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type SellExactInInstruction<
|
|
63
|
+
TProgram extends string = typeof SEND_DEX_PROGRAM_ADDRESS,
|
|
64
|
+
TAccountUser extends string | AccountMeta<string> = string,
|
|
65
|
+
TAccountPayer extends string | AccountMeta<string> = string,
|
|
66
|
+
TAccountPool extends string | AccountMeta<string> = string,
|
|
67
|
+
TAccountBaseMint extends string | AccountMeta<string> = string,
|
|
68
|
+
TAccountQuoteMint extends string | AccountMeta<string> = string,
|
|
69
|
+
TAccountBaseVault extends string | AccountMeta<string> = string,
|
|
70
|
+
TAccountQuoteVault extends string | AccountMeta<string> = string,
|
|
71
|
+
TAccountUserBaseAccount extends string | AccountMeta<string> = string,
|
|
72
|
+
TAccountUserQuoteAccount extends string | AccountMeta<string> = string,
|
|
73
|
+
TAccountPartner extends string | AccountMeta<string> = string,
|
|
74
|
+
TAccountPartnerConfig extends string | AccountMeta<string> = string,
|
|
75
|
+
TAccountBaseTokenProgram extends string | AccountMeta<string> =
|
|
76
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
|
|
77
|
+
TAccountQuoteTokenProgram extends string | AccountMeta<string> = string,
|
|
78
|
+
TAccountAssociatedTokenProgram extends string | AccountMeta<string> =
|
|
79
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
|
|
80
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
81
|
+
'11111111111111111111111111111111',
|
|
82
|
+
TAccountEventAuthority extends string | AccountMeta<string> =
|
|
83
|
+
'4pTDYKRFdmxTQYFceGZkzPGd3kb8ShMA9n6XKRaPZn8t',
|
|
84
|
+
TAccountProgram extends string | AccountMeta<string> =
|
|
85
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX',
|
|
86
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
87
|
+
> = Instruction<TProgram> &
|
|
88
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
89
|
+
InstructionWithAccounts<
|
|
90
|
+
[
|
|
91
|
+
TAccountUser extends string
|
|
92
|
+
? ReadonlySignerAccount<TAccountUser> &
|
|
93
|
+
AccountSignerMeta<TAccountUser>
|
|
94
|
+
: TAccountUser,
|
|
95
|
+
TAccountPayer extends string
|
|
96
|
+
? WritableSignerAccount<TAccountPayer> &
|
|
97
|
+
AccountSignerMeta<TAccountPayer>
|
|
98
|
+
: TAccountPayer,
|
|
99
|
+
TAccountPool extends string
|
|
100
|
+
? WritableAccount<TAccountPool>
|
|
101
|
+
: TAccountPool,
|
|
102
|
+
TAccountBaseMint extends string
|
|
103
|
+
? ReadonlyAccount<TAccountBaseMint>
|
|
104
|
+
: TAccountBaseMint,
|
|
105
|
+
TAccountQuoteMint extends string
|
|
106
|
+
? ReadonlyAccount<TAccountQuoteMint>
|
|
107
|
+
: TAccountQuoteMint,
|
|
108
|
+
TAccountBaseVault extends string
|
|
109
|
+
? WritableAccount<TAccountBaseVault>
|
|
110
|
+
: TAccountBaseVault,
|
|
111
|
+
TAccountQuoteVault extends string
|
|
112
|
+
? WritableAccount<TAccountQuoteVault>
|
|
113
|
+
: TAccountQuoteVault,
|
|
114
|
+
TAccountUserBaseAccount extends string
|
|
115
|
+
? WritableAccount<TAccountUserBaseAccount>
|
|
116
|
+
: TAccountUserBaseAccount,
|
|
117
|
+
TAccountUserQuoteAccount extends string
|
|
118
|
+
? WritableAccount<TAccountUserQuoteAccount>
|
|
119
|
+
: TAccountUserQuoteAccount,
|
|
120
|
+
TAccountPartner extends string
|
|
121
|
+
? ReadonlyAccount<TAccountPartner>
|
|
122
|
+
: TAccountPartner,
|
|
123
|
+
TAccountPartnerConfig extends string
|
|
124
|
+
? ReadonlyAccount<TAccountPartnerConfig>
|
|
125
|
+
: TAccountPartnerConfig,
|
|
126
|
+
TAccountBaseTokenProgram extends string
|
|
127
|
+
? ReadonlyAccount<TAccountBaseTokenProgram>
|
|
128
|
+
: TAccountBaseTokenProgram,
|
|
129
|
+
TAccountQuoteTokenProgram extends string
|
|
130
|
+
? ReadonlyAccount<TAccountQuoteTokenProgram>
|
|
131
|
+
: TAccountQuoteTokenProgram,
|
|
132
|
+
TAccountAssociatedTokenProgram extends string
|
|
133
|
+
? ReadonlyAccount<TAccountAssociatedTokenProgram>
|
|
134
|
+
: TAccountAssociatedTokenProgram,
|
|
135
|
+
TAccountSystemProgram extends string
|
|
136
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
137
|
+
: TAccountSystemProgram,
|
|
138
|
+
TAccountEventAuthority extends string
|
|
139
|
+
? ReadonlyAccount<TAccountEventAuthority>
|
|
140
|
+
: TAccountEventAuthority,
|
|
141
|
+
TAccountProgram extends string
|
|
142
|
+
? ReadonlyAccount<TAccountProgram>
|
|
143
|
+
: TAccountProgram,
|
|
144
|
+
...TRemainingAccounts,
|
|
145
|
+
]
|
|
146
|
+
>;
|
|
147
|
+
|
|
148
|
+
export type SellExactInInstructionData = {
|
|
149
|
+
discriminator: ReadonlyUint8Array;
|
|
150
|
+
amountIn: bigint;
|
|
151
|
+
minAmountOut: bigint;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type SellExactInInstructionDataArgs = {
|
|
155
|
+
amountIn: number | bigint;
|
|
156
|
+
minAmountOut: number | bigint;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export function getSellExactInInstructionDataEncoder(): FixedSizeEncoder<SellExactInInstructionDataArgs> {
|
|
160
|
+
return transformEncoder(
|
|
161
|
+
getStructEncoder([
|
|
162
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
163
|
+
['amountIn', getU64Encoder()],
|
|
164
|
+
['minAmountOut', getU64Encoder()],
|
|
165
|
+
]),
|
|
166
|
+
(value) => ({ ...value, discriminator: SELL_EXACT_IN_DISCRIMINATOR }),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getSellExactInInstructionDataDecoder(): FixedSizeDecoder<SellExactInInstructionData> {
|
|
171
|
+
return getStructDecoder([
|
|
172
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
173
|
+
['amountIn', getU64Decoder()],
|
|
174
|
+
['minAmountOut', getU64Decoder()],
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function getSellExactInInstructionDataCodec(): FixedSizeCodec<
|
|
179
|
+
SellExactInInstructionDataArgs,
|
|
180
|
+
SellExactInInstructionData
|
|
181
|
+
> {
|
|
182
|
+
return combineCodec(
|
|
183
|
+
getSellExactInInstructionDataEncoder(),
|
|
184
|
+
getSellExactInInstructionDataDecoder(),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type SellExactInInstructionExtraArgs = { platformConfig: Address };
|
|
189
|
+
|
|
190
|
+
export type SellExactInAsyncInput<
|
|
191
|
+
TAccountUser extends string = string,
|
|
192
|
+
TAccountPayer extends string = string,
|
|
193
|
+
TAccountPool extends string = string,
|
|
194
|
+
TAccountBaseMint extends string = string,
|
|
195
|
+
TAccountQuoteMint extends string = string,
|
|
196
|
+
TAccountBaseVault extends string = string,
|
|
197
|
+
TAccountQuoteVault extends string = string,
|
|
198
|
+
TAccountUserBaseAccount extends string = string,
|
|
199
|
+
TAccountUserQuoteAccount extends string = string,
|
|
200
|
+
TAccountPartner extends string = string,
|
|
201
|
+
TAccountPartnerConfig extends string = string,
|
|
202
|
+
TAccountQuoteTokenProgram extends string = string,
|
|
203
|
+
> = {
|
|
204
|
+
user: TransactionSigner<TAccountUser>;
|
|
205
|
+
payer: TransactionSigner<TAccountPayer>;
|
|
206
|
+
pool?: Address<TAccountPool>;
|
|
207
|
+
baseMint: Address<TAccountBaseMint>;
|
|
208
|
+
quoteMint: Address<TAccountQuoteMint>;
|
|
209
|
+
baseVault?: Address<TAccountBaseVault>;
|
|
210
|
+
quoteVault?: Address<TAccountQuoteVault>;
|
|
211
|
+
/** Optional: any base-mint account `user` owns; defaults to this ATA. */
|
|
212
|
+
userBaseAccount?: Address<TAccountUserBaseAccount>;
|
|
213
|
+
/** Optional: any quote-mint account `user` owns; defaults to this ATA. */
|
|
214
|
+
userQuoteAccount?: Address<TAccountUserQuoteAccount>;
|
|
215
|
+
/** The partner must sign. `DEFAULT_PARTNER`, the system program, does not sign. */
|
|
216
|
+
partner: Address<TAccountPartner> | TransactionSigner<TAccountPartner>;
|
|
217
|
+
partnerConfig?: Address<TAccountPartnerConfig>;
|
|
218
|
+
quoteTokenProgram: Address<TAccountQuoteTokenProgram>;
|
|
219
|
+
amountIn: SellExactInInstructionDataArgs['amountIn'];
|
|
220
|
+
minAmountOut: SellExactInInstructionDataArgs['minAmountOut'];
|
|
221
|
+
platformConfig: SellExactInInstructionExtraArgs['platformConfig'];
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export async function getSellExactInInstructionAsync<
|
|
225
|
+
TAccountUser extends string,
|
|
226
|
+
TAccountPayer extends string,
|
|
227
|
+
TAccountPool extends string,
|
|
228
|
+
TAccountBaseMint extends string,
|
|
229
|
+
TAccountQuoteMint extends string,
|
|
230
|
+
TAccountBaseVault extends string,
|
|
231
|
+
TAccountQuoteVault extends string,
|
|
232
|
+
TAccountUserBaseAccount extends string,
|
|
233
|
+
TAccountUserQuoteAccount extends string,
|
|
234
|
+
TAccountPartner extends string,
|
|
235
|
+
TAccountPartnerConfig extends string,
|
|
236
|
+
TAccountQuoteTokenProgram extends string,
|
|
237
|
+
>(
|
|
238
|
+
input: SellExactInAsyncInput<
|
|
239
|
+
TAccountUser,
|
|
240
|
+
TAccountPayer,
|
|
241
|
+
TAccountPool,
|
|
242
|
+
TAccountBaseMint,
|
|
243
|
+
TAccountQuoteMint,
|
|
244
|
+
TAccountBaseVault,
|
|
245
|
+
TAccountQuoteVault,
|
|
246
|
+
TAccountUserBaseAccount,
|
|
247
|
+
TAccountUserQuoteAccount,
|
|
248
|
+
TAccountPartner,
|
|
249
|
+
TAccountPartnerConfig,
|
|
250
|
+
TAccountQuoteTokenProgram
|
|
251
|
+
>,
|
|
252
|
+
): Promise<
|
|
253
|
+
SellExactInInstruction<
|
|
254
|
+
typeof SEND_DEX_PROGRAM_ADDRESS,
|
|
255
|
+
TAccountUser,
|
|
256
|
+
TAccountPayer,
|
|
257
|
+
TAccountPool,
|
|
258
|
+
TAccountBaseMint,
|
|
259
|
+
TAccountQuoteMint,
|
|
260
|
+
TAccountBaseVault,
|
|
261
|
+
TAccountQuoteVault,
|
|
262
|
+
TAccountUserBaseAccount,
|
|
263
|
+
TAccountUserQuoteAccount,
|
|
264
|
+
(typeof input)['partner'] extends TransactionSigner<TAccountPartner>
|
|
265
|
+
? ReadonlySignerAccount<TAccountPartner> &
|
|
266
|
+
AccountSignerMeta<TAccountPartner>
|
|
267
|
+
: TAccountPartner,
|
|
268
|
+
TAccountPartnerConfig,
|
|
269
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
|
|
270
|
+
TAccountQuoteTokenProgram,
|
|
271
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
|
|
272
|
+
'11111111111111111111111111111111',
|
|
273
|
+
'4pTDYKRFdmxTQYFceGZkzPGd3kb8ShMA9n6XKRaPZn8t',
|
|
274
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'
|
|
275
|
+
>
|
|
276
|
+
> {
|
|
277
|
+
// Program address.
|
|
278
|
+
const programAddress = SEND_DEX_PROGRAM_ADDRESS;
|
|
279
|
+
|
|
280
|
+
// Original accounts.
|
|
281
|
+
const originalAccounts = {
|
|
282
|
+
user: { value: input.user ?? null, isWritable: false },
|
|
283
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
284
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
285
|
+
baseMint: { value: input.baseMint ?? null, isWritable: false },
|
|
286
|
+
quoteMint: { value: input.quoteMint ?? null, isWritable: false },
|
|
287
|
+
baseVault: { value: input.baseVault ?? null, isWritable: true },
|
|
288
|
+
quoteVault: { value: input.quoteVault ?? null, isWritable: true },
|
|
289
|
+
userBaseAccount: {
|
|
290
|
+
value: input.userBaseAccount ?? null,
|
|
291
|
+
isWritable: true,
|
|
292
|
+
},
|
|
293
|
+
userQuoteAccount: {
|
|
294
|
+
value: input.userQuoteAccount ?? null,
|
|
295
|
+
isWritable: true,
|
|
296
|
+
},
|
|
297
|
+
partner: { value: input.partner ?? null, isWritable: false },
|
|
298
|
+
partnerConfig: {
|
|
299
|
+
value: input.partnerConfig ?? null,
|
|
300
|
+
isWritable: false,
|
|
301
|
+
},
|
|
302
|
+
baseTokenProgram: { value: null, isWritable: false },
|
|
303
|
+
quoteTokenProgram: {
|
|
304
|
+
value: input.quoteTokenProgram ?? null,
|
|
305
|
+
isWritable: false,
|
|
306
|
+
},
|
|
307
|
+
associatedTokenProgram: { value: null, isWritable: false },
|
|
308
|
+
systemProgram: { value: null, isWritable: false },
|
|
309
|
+
eventAuthority: { value: null, isWritable: false },
|
|
310
|
+
program: { value: null, isWritable: false },
|
|
311
|
+
};
|
|
312
|
+
const accounts = originalAccounts as Record<
|
|
313
|
+
keyof typeof originalAccounts,
|
|
314
|
+
ResolvedInstructionAccount
|
|
315
|
+
>;
|
|
316
|
+
|
|
317
|
+
// Original args.
|
|
318
|
+
const args = { ...input };
|
|
319
|
+
|
|
320
|
+
// Resolve default values.
|
|
321
|
+
if (!accounts.pool.value) {
|
|
322
|
+
accounts.pool.value = await findPoolPda({
|
|
323
|
+
baseMint: getAddressFromResolvedInstructionAccount(
|
|
324
|
+
'baseMint',
|
|
325
|
+
accounts.baseMint.value,
|
|
326
|
+
),
|
|
327
|
+
quoteMint: getAddressFromResolvedInstructionAccount(
|
|
328
|
+
'quoteMint',
|
|
329
|
+
accounts.quoteMint.value,
|
|
330
|
+
),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
if (!accounts.baseVault.value) {
|
|
334
|
+
accounts.baseVault.value = await getProgramDerivedAddress({
|
|
335
|
+
programAddress:
|
|
336
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>,
|
|
337
|
+
seeds: [
|
|
338
|
+
getAddressEncoder().encode(
|
|
339
|
+
getAddressFromResolvedInstructionAccount(
|
|
340
|
+
'pool',
|
|
341
|
+
accounts.pool.value,
|
|
342
|
+
),
|
|
343
|
+
),
|
|
344
|
+
getAddressEncoder().encode(
|
|
345
|
+
address('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'),
|
|
346
|
+
),
|
|
347
|
+
getAddressEncoder().encode(
|
|
348
|
+
getAddressFromResolvedInstructionAccount(
|
|
349
|
+
'baseMint',
|
|
350
|
+
accounts.baseMint.value,
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
],
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (!accounts.quoteVault.value) {
|
|
357
|
+
accounts.quoteVault.value = await getProgramDerivedAddress({
|
|
358
|
+
programAddress:
|
|
359
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>,
|
|
360
|
+
seeds: [
|
|
361
|
+
getAddressEncoder().encode(
|
|
362
|
+
getAddressFromResolvedInstructionAccount(
|
|
363
|
+
'pool',
|
|
364
|
+
accounts.pool.value,
|
|
365
|
+
),
|
|
366
|
+
),
|
|
367
|
+
getAddressEncoder().encode(
|
|
368
|
+
getAddressFromResolvedInstructionAccount(
|
|
369
|
+
'quoteTokenProgram',
|
|
370
|
+
accounts.quoteTokenProgram.value,
|
|
371
|
+
),
|
|
372
|
+
),
|
|
373
|
+
getAddressEncoder().encode(
|
|
374
|
+
getAddressFromResolvedInstructionAccount(
|
|
375
|
+
'quoteMint',
|
|
376
|
+
accounts.quoteMint.value,
|
|
377
|
+
),
|
|
378
|
+
),
|
|
379
|
+
],
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
if (!accounts.userBaseAccount.value) {
|
|
383
|
+
accounts.userBaseAccount.value = await getProgramDerivedAddress({
|
|
384
|
+
programAddress:
|
|
385
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>,
|
|
386
|
+
seeds: [
|
|
387
|
+
getAddressEncoder().encode(
|
|
388
|
+
getAddressFromResolvedInstructionAccount(
|
|
389
|
+
'user',
|
|
390
|
+
accounts.user.value,
|
|
391
|
+
),
|
|
392
|
+
),
|
|
393
|
+
getAddressEncoder().encode(
|
|
394
|
+
address('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'),
|
|
395
|
+
),
|
|
396
|
+
getAddressEncoder().encode(
|
|
397
|
+
getAddressFromResolvedInstructionAccount(
|
|
398
|
+
'baseMint',
|
|
399
|
+
accounts.baseMint.value,
|
|
400
|
+
),
|
|
401
|
+
),
|
|
402
|
+
],
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (!accounts.userQuoteAccount.value) {
|
|
406
|
+
accounts.userQuoteAccount.value = await getProgramDerivedAddress({
|
|
407
|
+
programAddress:
|
|
408
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>,
|
|
409
|
+
seeds: [
|
|
410
|
+
getAddressEncoder().encode(
|
|
411
|
+
getAddressFromResolvedInstructionAccount(
|
|
412
|
+
'user',
|
|
413
|
+
accounts.user.value,
|
|
414
|
+
),
|
|
415
|
+
),
|
|
416
|
+
getAddressEncoder().encode(
|
|
417
|
+
getAddressFromResolvedInstructionAccount(
|
|
418
|
+
'quoteTokenProgram',
|
|
419
|
+
accounts.quoteTokenProgram.value,
|
|
420
|
+
),
|
|
421
|
+
),
|
|
422
|
+
getAddressEncoder().encode(
|
|
423
|
+
getAddressFromResolvedInstructionAccount(
|
|
424
|
+
'quoteMint',
|
|
425
|
+
accounts.quoteMint.value,
|
|
426
|
+
),
|
|
427
|
+
),
|
|
428
|
+
],
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
if (!accounts.partnerConfig.value) {
|
|
432
|
+
accounts.partnerConfig.value = await getProgramDerivedAddress({
|
|
433
|
+
programAddress:
|
|
434
|
+
'7rrCurqdWFesbzwtYPo95fM8waTtVXgXwCom45x1sfNX' as Address<'7rrCurqdWFesbzwtYPo95fM8waTtVXgXwCom45x1sfNX'>,
|
|
435
|
+
seeds: [
|
|
436
|
+
getBytesEncoder().encode(
|
|
437
|
+
new Uint8Array([112, 97, 114, 116, 110, 101, 114]),
|
|
438
|
+
),
|
|
439
|
+
getAddressEncoder().encode(
|
|
440
|
+
getNonNullResolvedInstructionInput(
|
|
441
|
+
'platformConfig',
|
|
442
|
+
args.platformConfig,
|
|
443
|
+
),
|
|
444
|
+
),
|
|
445
|
+
getAddressEncoder().encode(
|
|
446
|
+
getAddressFromResolvedInstructionAccount(
|
|
447
|
+
'partner',
|
|
448
|
+
accounts.partner.value,
|
|
449
|
+
),
|
|
450
|
+
),
|
|
451
|
+
],
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
if (!accounts.baseTokenProgram.value) {
|
|
455
|
+
accounts.baseTokenProgram.value =
|
|
456
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
|
|
457
|
+
}
|
|
458
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
459
|
+
accounts.associatedTokenProgram.value =
|
|
460
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>;
|
|
461
|
+
}
|
|
462
|
+
if (!accounts.systemProgram.value) {
|
|
463
|
+
accounts.systemProgram.value =
|
|
464
|
+
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
465
|
+
}
|
|
466
|
+
if (!accounts.eventAuthority.value) {
|
|
467
|
+
accounts.eventAuthority.value = EVENT_AUTHORITY_PDA_ADDRESS;
|
|
468
|
+
}
|
|
469
|
+
if (!accounts.program.value) {
|
|
470
|
+
accounts.program.value =
|
|
471
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX' as Address<'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'>;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
475
|
+
return Object.freeze({
|
|
476
|
+
accounts: [
|
|
477
|
+
getAccountMeta('user', accounts.user),
|
|
478
|
+
getAccountMeta('payer', accounts.payer),
|
|
479
|
+
getAccountMeta('pool', accounts.pool),
|
|
480
|
+
getAccountMeta('baseMint', accounts.baseMint),
|
|
481
|
+
getAccountMeta('quoteMint', accounts.quoteMint),
|
|
482
|
+
getAccountMeta('baseVault', accounts.baseVault),
|
|
483
|
+
getAccountMeta('quoteVault', accounts.quoteVault),
|
|
484
|
+
getAccountMeta('userBaseAccount', accounts.userBaseAccount),
|
|
485
|
+
getAccountMeta('userQuoteAccount', accounts.userQuoteAccount),
|
|
486
|
+
getAccountMeta('partner', accounts.partner),
|
|
487
|
+
getAccountMeta('partnerConfig', accounts.partnerConfig),
|
|
488
|
+
getAccountMeta('baseTokenProgram', accounts.baseTokenProgram),
|
|
489
|
+
getAccountMeta('quoteTokenProgram', accounts.quoteTokenProgram),
|
|
490
|
+
getAccountMeta(
|
|
491
|
+
'associatedTokenProgram',
|
|
492
|
+
accounts.associatedTokenProgram,
|
|
493
|
+
),
|
|
494
|
+
getAccountMeta('systemProgram', accounts.systemProgram),
|
|
495
|
+
getAccountMeta('eventAuthority', accounts.eventAuthority),
|
|
496
|
+
getAccountMeta('program', accounts.program),
|
|
497
|
+
],
|
|
498
|
+
data: getSellExactInInstructionDataEncoder().encode(
|
|
499
|
+
args as SellExactInInstructionDataArgs,
|
|
500
|
+
),
|
|
501
|
+
programAddress,
|
|
502
|
+
} as SellExactInInstruction<
|
|
503
|
+
typeof SEND_DEX_PROGRAM_ADDRESS,
|
|
504
|
+
TAccountUser,
|
|
505
|
+
TAccountPayer,
|
|
506
|
+
TAccountPool,
|
|
507
|
+
TAccountBaseMint,
|
|
508
|
+
TAccountQuoteMint,
|
|
509
|
+
TAccountBaseVault,
|
|
510
|
+
TAccountQuoteVault,
|
|
511
|
+
TAccountUserBaseAccount,
|
|
512
|
+
TAccountUserQuoteAccount,
|
|
513
|
+
(typeof input)['partner'] extends TransactionSigner<TAccountPartner>
|
|
514
|
+
? ReadonlySignerAccount<TAccountPartner> &
|
|
515
|
+
AccountSignerMeta<TAccountPartner>
|
|
516
|
+
: TAccountPartner,
|
|
517
|
+
TAccountPartnerConfig,
|
|
518
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
|
|
519
|
+
TAccountQuoteTokenProgram,
|
|
520
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
|
|
521
|
+
'11111111111111111111111111111111',
|
|
522
|
+
'4pTDYKRFdmxTQYFceGZkzPGd3kb8ShMA9n6XKRaPZn8t',
|
|
523
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'
|
|
524
|
+
>);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export type SellExactInInput<
|
|
528
|
+
TAccountUser extends string = string,
|
|
529
|
+
TAccountPayer extends string = string,
|
|
530
|
+
TAccountPool extends string = string,
|
|
531
|
+
TAccountBaseMint extends string = string,
|
|
532
|
+
TAccountQuoteMint extends string = string,
|
|
533
|
+
TAccountBaseVault extends string = string,
|
|
534
|
+
TAccountQuoteVault extends string = string,
|
|
535
|
+
TAccountUserBaseAccount extends string = string,
|
|
536
|
+
TAccountUserQuoteAccount extends string = string,
|
|
537
|
+
TAccountPartner extends string = string,
|
|
538
|
+
TAccountPartnerConfig extends string = string,
|
|
539
|
+
TAccountQuoteTokenProgram extends string = string,
|
|
540
|
+
> = {
|
|
541
|
+
user: TransactionSigner<TAccountUser>;
|
|
542
|
+
payer: TransactionSigner<TAccountPayer>;
|
|
543
|
+
pool: Address<TAccountPool>;
|
|
544
|
+
baseMint: Address<TAccountBaseMint>;
|
|
545
|
+
quoteMint: Address<TAccountQuoteMint>;
|
|
546
|
+
baseVault: Address<TAccountBaseVault>;
|
|
547
|
+
quoteVault: Address<TAccountQuoteVault>;
|
|
548
|
+
/** Optional: any base-mint account `user` owns; defaults to this ATA. */
|
|
549
|
+
userBaseAccount: Address<TAccountUserBaseAccount>;
|
|
550
|
+
/** Optional: any quote-mint account `user` owns; defaults to this ATA. */
|
|
551
|
+
userQuoteAccount: Address<TAccountUserQuoteAccount>;
|
|
552
|
+
/** The partner must sign. `DEFAULT_PARTNER`, the system program, does not sign. */
|
|
553
|
+
partner: Address<TAccountPartner> | TransactionSigner<TAccountPartner>;
|
|
554
|
+
partnerConfig: Address<TAccountPartnerConfig>;
|
|
555
|
+
quoteTokenProgram: Address<TAccountQuoteTokenProgram>;
|
|
556
|
+
amountIn: SellExactInInstructionDataArgs['amountIn'];
|
|
557
|
+
minAmountOut: SellExactInInstructionDataArgs['minAmountOut'];
|
|
558
|
+
platformConfig?: SellExactInInstructionExtraArgs['platformConfig'];
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
export function getSellExactInInstruction<
|
|
562
|
+
TAccountUser extends string,
|
|
563
|
+
TAccountPayer extends string,
|
|
564
|
+
TAccountPool extends string,
|
|
565
|
+
TAccountBaseMint extends string,
|
|
566
|
+
TAccountQuoteMint extends string,
|
|
567
|
+
TAccountBaseVault extends string,
|
|
568
|
+
TAccountQuoteVault extends string,
|
|
569
|
+
TAccountUserBaseAccount extends string,
|
|
570
|
+
TAccountUserQuoteAccount extends string,
|
|
571
|
+
TAccountPartner extends string,
|
|
572
|
+
TAccountPartnerConfig extends string,
|
|
573
|
+
TAccountQuoteTokenProgram extends string,
|
|
574
|
+
>(
|
|
575
|
+
input: SellExactInInput<
|
|
576
|
+
TAccountUser,
|
|
577
|
+
TAccountPayer,
|
|
578
|
+
TAccountPool,
|
|
579
|
+
TAccountBaseMint,
|
|
580
|
+
TAccountQuoteMint,
|
|
581
|
+
TAccountBaseVault,
|
|
582
|
+
TAccountQuoteVault,
|
|
583
|
+
TAccountUserBaseAccount,
|
|
584
|
+
TAccountUserQuoteAccount,
|
|
585
|
+
TAccountPartner,
|
|
586
|
+
TAccountPartnerConfig,
|
|
587
|
+
TAccountQuoteTokenProgram
|
|
588
|
+
>,
|
|
589
|
+
): SellExactInInstruction<
|
|
590
|
+
typeof SEND_DEX_PROGRAM_ADDRESS,
|
|
591
|
+
TAccountUser,
|
|
592
|
+
TAccountPayer,
|
|
593
|
+
TAccountPool,
|
|
594
|
+
TAccountBaseMint,
|
|
595
|
+
TAccountQuoteMint,
|
|
596
|
+
TAccountBaseVault,
|
|
597
|
+
TAccountQuoteVault,
|
|
598
|
+
TAccountUserBaseAccount,
|
|
599
|
+
TAccountUserQuoteAccount,
|
|
600
|
+
(typeof input)['partner'] extends TransactionSigner<TAccountPartner>
|
|
601
|
+
? ReadonlySignerAccount<TAccountPartner> &
|
|
602
|
+
AccountSignerMeta<TAccountPartner>
|
|
603
|
+
: TAccountPartner,
|
|
604
|
+
TAccountPartnerConfig,
|
|
605
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
|
|
606
|
+
TAccountQuoteTokenProgram,
|
|
607
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
|
|
608
|
+
'11111111111111111111111111111111',
|
|
609
|
+
'4pTDYKRFdmxTQYFceGZkzPGd3kb8ShMA9n6XKRaPZn8t',
|
|
610
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'
|
|
611
|
+
> {
|
|
612
|
+
// Program address.
|
|
613
|
+
const programAddress = SEND_DEX_PROGRAM_ADDRESS;
|
|
614
|
+
|
|
615
|
+
// Original accounts.
|
|
616
|
+
const originalAccounts = {
|
|
617
|
+
user: { value: input.user ?? null, isWritable: false },
|
|
618
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
619
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
620
|
+
baseMint: { value: input.baseMint ?? null, isWritable: false },
|
|
621
|
+
quoteMint: { value: input.quoteMint ?? null, isWritable: false },
|
|
622
|
+
baseVault: { value: input.baseVault ?? null, isWritable: true },
|
|
623
|
+
quoteVault: { value: input.quoteVault ?? null, isWritable: true },
|
|
624
|
+
userBaseAccount: {
|
|
625
|
+
value: input.userBaseAccount ?? null,
|
|
626
|
+
isWritable: true,
|
|
627
|
+
},
|
|
628
|
+
userQuoteAccount: {
|
|
629
|
+
value: input.userQuoteAccount ?? null,
|
|
630
|
+
isWritable: true,
|
|
631
|
+
},
|
|
632
|
+
partner: { value: input.partner ?? null, isWritable: false },
|
|
633
|
+
partnerConfig: {
|
|
634
|
+
value: input.partnerConfig ?? null,
|
|
635
|
+
isWritable: false,
|
|
636
|
+
},
|
|
637
|
+
baseTokenProgram: { value: null, isWritable: false },
|
|
638
|
+
quoteTokenProgram: {
|
|
639
|
+
value: input.quoteTokenProgram ?? null,
|
|
640
|
+
isWritable: false,
|
|
641
|
+
},
|
|
642
|
+
associatedTokenProgram: { value: null, isWritable: false },
|
|
643
|
+
systemProgram: { value: null, isWritable: false },
|
|
644
|
+
eventAuthority: { value: null, isWritable: false },
|
|
645
|
+
program: { value: null, isWritable: false },
|
|
646
|
+
};
|
|
647
|
+
const accounts = originalAccounts as Record<
|
|
648
|
+
keyof typeof originalAccounts,
|
|
649
|
+
ResolvedInstructionAccount
|
|
650
|
+
>;
|
|
651
|
+
|
|
652
|
+
// Original args.
|
|
653
|
+
const args = { ...input };
|
|
654
|
+
|
|
655
|
+
// Resolve default values.
|
|
656
|
+
if (!accounts.baseTokenProgram.value) {
|
|
657
|
+
accounts.baseTokenProgram.value =
|
|
658
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
|
|
659
|
+
}
|
|
660
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
661
|
+
accounts.associatedTokenProgram.value =
|
|
662
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>;
|
|
663
|
+
}
|
|
664
|
+
if (!accounts.systemProgram.value) {
|
|
665
|
+
accounts.systemProgram.value =
|
|
666
|
+
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
667
|
+
}
|
|
668
|
+
if (!accounts.eventAuthority.value) {
|
|
669
|
+
accounts.eventAuthority.value = EVENT_AUTHORITY_PDA_ADDRESS;
|
|
670
|
+
}
|
|
671
|
+
if (!accounts.program.value) {
|
|
672
|
+
accounts.program.value =
|
|
673
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX' as Address<'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'>;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
677
|
+
return Object.freeze({
|
|
678
|
+
accounts: [
|
|
679
|
+
getAccountMeta('user', accounts.user),
|
|
680
|
+
getAccountMeta('payer', accounts.payer),
|
|
681
|
+
getAccountMeta('pool', accounts.pool),
|
|
682
|
+
getAccountMeta('baseMint', accounts.baseMint),
|
|
683
|
+
getAccountMeta('quoteMint', accounts.quoteMint),
|
|
684
|
+
getAccountMeta('baseVault', accounts.baseVault),
|
|
685
|
+
getAccountMeta('quoteVault', accounts.quoteVault),
|
|
686
|
+
getAccountMeta('userBaseAccount', accounts.userBaseAccount),
|
|
687
|
+
getAccountMeta('userQuoteAccount', accounts.userQuoteAccount),
|
|
688
|
+
getAccountMeta('partner', accounts.partner),
|
|
689
|
+
getAccountMeta('partnerConfig', accounts.partnerConfig),
|
|
690
|
+
getAccountMeta('baseTokenProgram', accounts.baseTokenProgram),
|
|
691
|
+
getAccountMeta('quoteTokenProgram', accounts.quoteTokenProgram),
|
|
692
|
+
getAccountMeta(
|
|
693
|
+
'associatedTokenProgram',
|
|
694
|
+
accounts.associatedTokenProgram,
|
|
695
|
+
),
|
|
696
|
+
getAccountMeta('systemProgram', accounts.systemProgram),
|
|
697
|
+
getAccountMeta('eventAuthority', accounts.eventAuthority),
|
|
698
|
+
getAccountMeta('program', accounts.program),
|
|
699
|
+
],
|
|
700
|
+
data: getSellExactInInstructionDataEncoder().encode(
|
|
701
|
+
args as SellExactInInstructionDataArgs,
|
|
702
|
+
),
|
|
703
|
+
programAddress,
|
|
704
|
+
} as SellExactInInstruction<
|
|
705
|
+
typeof SEND_DEX_PROGRAM_ADDRESS,
|
|
706
|
+
TAccountUser,
|
|
707
|
+
TAccountPayer,
|
|
708
|
+
TAccountPool,
|
|
709
|
+
TAccountBaseMint,
|
|
710
|
+
TAccountQuoteMint,
|
|
711
|
+
TAccountBaseVault,
|
|
712
|
+
TAccountQuoteVault,
|
|
713
|
+
TAccountUserBaseAccount,
|
|
714
|
+
TAccountUserQuoteAccount,
|
|
715
|
+
(typeof input)['partner'] extends TransactionSigner<TAccountPartner>
|
|
716
|
+
? ReadonlySignerAccount<TAccountPartner> &
|
|
717
|
+
AccountSignerMeta<TAccountPartner>
|
|
718
|
+
: TAccountPartner,
|
|
719
|
+
TAccountPartnerConfig,
|
|
720
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
|
|
721
|
+
TAccountQuoteTokenProgram,
|
|
722
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
|
|
723
|
+
'11111111111111111111111111111111',
|
|
724
|
+
'4pTDYKRFdmxTQYFceGZkzPGd3kb8ShMA9n6XKRaPZn8t',
|
|
725
|
+
'84qj5FPZZdXkQy8mfowyg6RBZ3XKuTds6XS4ZYT1sfDX'
|
|
726
|
+
>);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export type ParsedSellExactInInstruction<
|
|
730
|
+
TProgram extends string = typeof SEND_DEX_PROGRAM_ADDRESS,
|
|
731
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
732
|
+
> = {
|
|
733
|
+
programAddress: Address<TProgram>;
|
|
734
|
+
accounts: {
|
|
735
|
+
user: TAccountMetas[0];
|
|
736
|
+
payer: TAccountMetas[1];
|
|
737
|
+
pool: TAccountMetas[2];
|
|
738
|
+
baseMint: TAccountMetas[3];
|
|
739
|
+
quoteMint: TAccountMetas[4];
|
|
740
|
+
baseVault: TAccountMetas[5];
|
|
741
|
+
quoteVault: TAccountMetas[6];
|
|
742
|
+
/** Optional: any base-mint account `user` owns; defaults to this ATA. */
|
|
743
|
+
userBaseAccount: TAccountMetas[7];
|
|
744
|
+
/** Optional: any quote-mint account `user` owns; defaults to this ATA. */
|
|
745
|
+
userQuoteAccount: TAccountMetas[8];
|
|
746
|
+
/** The partner must sign. `DEFAULT_PARTNER`, the system program, does not sign. */
|
|
747
|
+
partner: TAccountMetas[9];
|
|
748
|
+
partnerConfig: TAccountMetas[10];
|
|
749
|
+
baseTokenProgram: TAccountMetas[11];
|
|
750
|
+
quoteTokenProgram: TAccountMetas[12];
|
|
751
|
+
associatedTokenProgram: TAccountMetas[13];
|
|
752
|
+
systemProgram: TAccountMetas[14];
|
|
753
|
+
eventAuthority: TAccountMetas[15];
|
|
754
|
+
program: TAccountMetas[16];
|
|
755
|
+
};
|
|
756
|
+
data: SellExactInInstructionData;
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
export function parseSellExactInInstruction<
|
|
760
|
+
TProgram extends string,
|
|
761
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
762
|
+
>(
|
|
763
|
+
instruction: Instruction<TProgram> &
|
|
764
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
765
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
766
|
+
): ParsedSellExactInInstruction<TProgram, TAccountMetas> {
|
|
767
|
+
assertIsInstructionForProgram(instruction, SEND_DEX_PROGRAM_ADDRESS);
|
|
768
|
+
if (!containsBytes(instruction.data, SELL_EXACT_IN_DISCRIMINATOR, 0)) {
|
|
769
|
+
const error = new Error(
|
|
770
|
+
`parseSellExactInInstruction: instruction data does not match the SellExactIn discriminator`,
|
|
771
|
+
);
|
|
772
|
+
error.name = 'InstructionDiscriminatorMismatchError';
|
|
773
|
+
throw error;
|
|
774
|
+
}
|
|
775
|
+
if (instruction.accounts.length < 17) {
|
|
776
|
+
throw new SolanaError(
|
|
777
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
778
|
+
{
|
|
779
|
+
actualAccountMetas: instruction.accounts.length,
|
|
780
|
+
expectedAccountMetas: 17,
|
|
781
|
+
},
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
let accountIndex = 0;
|
|
785
|
+
const getNextAccount = () => {
|
|
786
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[
|
|
787
|
+
accountIndex
|
|
788
|
+
]!;
|
|
789
|
+
accountIndex += 1;
|
|
790
|
+
return accountMeta;
|
|
791
|
+
};
|
|
792
|
+
return {
|
|
793
|
+
programAddress: instruction.programAddress,
|
|
794
|
+
accounts: {
|
|
795
|
+
user: getNextAccount(),
|
|
796
|
+
payer: getNextAccount(),
|
|
797
|
+
pool: getNextAccount(),
|
|
798
|
+
baseMint: getNextAccount(),
|
|
799
|
+
quoteMint: getNextAccount(),
|
|
800
|
+
baseVault: getNextAccount(),
|
|
801
|
+
quoteVault: getNextAccount(),
|
|
802
|
+
userBaseAccount: getNextAccount(),
|
|
803
|
+
userQuoteAccount: getNextAccount(),
|
|
804
|
+
partner: getNextAccount(),
|
|
805
|
+
partnerConfig: getNextAccount(),
|
|
806
|
+
baseTokenProgram: getNextAccount(),
|
|
807
|
+
quoteTokenProgram: getNextAccount(),
|
|
808
|
+
associatedTokenProgram: getNextAccount(),
|
|
809
|
+
systemProgram: getNextAccount(),
|
|
810
|
+
eventAuthority: getNextAccount(),
|
|
811
|
+
program: getNextAccount(),
|
|
812
|
+
},
|
|
813
|
+
data: getSellExactInInstructionDataDecoder().decode(instruction.data),
|
|
814
|
+
};
|
|
815
|
+
}
|