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