@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,498 @@
|
|
|
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
|
+
assertIsInstructionForProgram,
|
|
11
|
+
combineCodec,
|
|
12
|
+
containsBytes,
|
|
13
|
+
fixDecoderSize,
|
|
14
|
+
fixEncoderSize,
|
|
15
|
+
getBytesDecoder,
|
|
16
|
+
getBytesEncoder,
|
|
17
|
+
getStructDecoder,
|
|
18
|
+
getStructEncoder,
|
|
19
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
20
|
+
SolanaError,
|
|
21
|
+
transformEncoder,
|
|
22
|
+
type AccountMeta,
|
|
23
|
+
type AccountSignerMeta,
|
|
24
|
+
type Address,
|
|
25
|
+
type FixedSizeCodec,
|
|
26
|
+
type FixedSizeDecoder,
|
|
27
|
+
type FixedSizeEncoder,
|
|
28
|
+
type Instruction,
|
|
29
|
+
type InstructionWithAccounts,
|
|
30
|
+
type InstructionWithData,
|
|
31
|
+
type ReadonlyAccount,
|
|
32
|
+
type ReadonlyUint8Array,
|
|
33
|
+
type TransactionSigner,
|
|
34
|
+
type WritableAccount,
|
|
35
|
+
type WritableSignerAccount,
|
|
36
|
+
} from '@solana/kit';
|
|
37
|
+
import {
|
|
38
|
+
getAccountMetaFactory,
|
|
39
|
+
getAddressFromResolvedInstructionAccount,
|
|
40
|
+
type ResolvedInstructionAccount,
|
|
41
|
+
} from '@solana/program-client-core';
|
|
42
|
+
import {
|
|
43
|
+
findRewardStatePda,
|
|
44
|
+
findUserRewardDebtPda,
|
|
45
|
+
findUserStakePositionPda,
|
|
46
|
+
STAKING_CONFIG_PDA_ADDRESS,
|
|
47
|
+
} from '../pdas/index.js';
|
|
48
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
49
|
+
|
|
50
|
+
export const CREATE_USER_REWARD_DEBT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
51
|
+
new Uint8Array([155, 124, 113, 190, 252, 235, 113, 155]);
|
|
52
|
+
|
|
53
|
+
export function getCreateUserRewardDebtDiscriminatorBytes(): ReadonlyUint8Array {
|
|
54
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
55
|
+
CREATE_USER_REWARD_DEBT_DISCRIMINATOR,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type CreateUserRewardDebtInstruction<
|
|
60
|
+
TProgram extends string = typeof SEND_NEXUS_PROGRAM_ADDRESS,
|
|
61
|
+
TAccountUser extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountPayer extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountStakingMint extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountRewardMint extends string | AccountMeta<string> = string,
|
|
65
|
+
TAccountStakingConfig extends string | AccountMeta<string> =
|
|
66
|
+
'9WUowYRb6KAWjWVB5KMmTngBidZXEXgQcQRTXbhxeGbF',
|
|
67
|
+
TAccountRewardState extends string | AccountMeta<string> = string,
|
|
68
|
+
TAccountUserStakePosition extends string | AccountMeta<string> = string,
|
|
69
|
+
TAccountUserRewardDebt extends string | AccountMeta<string> = string,
|
|
70
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
71
|
+
'11111111111111111111111111111111',
|
|
72
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
73
|
+
> = Instruction<TProgram> &
|
|
74
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
75
|
+
InstructionWithAccounts<
|
|
76
|
+
[
|
|
77
|
+
TAccountUser extends string
|
|
78
|
+
? ReadonlyAccount<TAccountUser>
|
|
79
|
+
: TAccountUser,
|
|
80
|
+
TAccountPayer extends string
|
|
81
|
+
? WritableSignerAccount<TAccountPayer> &
|
|
82
|
+
AccountSignerMeta<TAccountPayer>
|
|
83
|
+
: TAccountPayer,
|
|
84
|
+
TAccountStakingMint extends string
|
|
85
|
+
? ReadonlyAccount<TAccountStakingMint>
|
|
86
|
+
: TAccountStakingMint,
|
|
87
|
+
TAccountRewardMint extends string
|
|
88
|
+
? ReadonlyAccount<TAccountRewardMint>
|
|
89
|
+
: TAccountRewardMint,
|
|
90
|
+
TAccountStakingConfig extends string
|
|
91
|
+
? ReadonlyAccount<TAccountStakingConfig>
|
|
92
|
+
: TAccountStakingConfig,
|
|
93
|
+
TAccountRewardState extends string
|
|
94
|
+
? ReadonlyAccount<TAccountRewardState>
|
|
95
|
+
: TAccountRewardState,
|
|
96
|
+
TAccountUserStakePosition extends string
|
|
97
|
+
? WritableAccount<TAccountUserStakePosition>
|
|
98
|
+
: TAccountUserStakePosition,
|
|
99
|
+
TAccountUserRewardDebt extends string
|
|
100
|
+
? WritableAccount<TAccountUserRewardDebt>
|
|
101
|
+
: TAccountUserRewardDebt,
|
|
102
|
+
TAccountSystemProgram extends string
|
|
103
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
104
|
+
: TAccountSystemProgram,
|
|
105
|
+
...TRemainingAccounts,
|
|
106
|
+
]
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
export type CreateUserRewardDebtInstructionData = {
|
|
110
|
+
discriminator: ReadonlyUint8Array;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type CreateUserRewardDebtInstructionDataArgs = {};
|
|
114
|
+
|
|
115
|
+
export function getCreateUserRewardDebtInstructionDataEncoder(): FixedSizeEncoder<CreateUserRewardDebtInstructionDataArgs> {
|
|
116
|
+
return transformEncoder(
|
|
117
|
+
getStructEncoder([
|
|
118
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
119
|
+
]),
|
|
120
|
+
(value) => ({
|
|
121
|
+
...value,
|
|
122
|
+
discriminator: CREATE_USER_REWARD_DEBT_DISCRIMINATOR,
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function getCreateUserRewardDebtInstructionDataDecoder(): FixedSizeDecoder<CreateUserRewardDebtInstructionData> {
|
|
128
|
+
return getStructDecoder([
|
|
129
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function getCreateUserRewardDebtInstructionDataCodec(): FixedSizeCodec<
|
|
134
|
+
CreateUserRewardDebtInstructionDataArgs,
|
|
135
|
+
CreateUserRewardDebtInstructionData
|
|
136
|
+
> {
|
|
137
|
+
return combineCodec(
|
|
138
|
+
getCreateUserRewardDebtInstructionDataEncoder(),
|
|
139
|
+
getCreateUserRewardDebtInstructionDataDecoder(),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type CreateUserRewardDebtAsyncInput<
|
|
144
|
+
TAccountUser extends string = string,
|
|
145
|
+
TAccountPayer extends string = string,
|
|
146
|
+
TAccountStakingMint extends string = string,
|
|
147
|
+
TAccountRewardMint extends string = string,
|
|
148
|
+
TAccountStakingConfig extends string = string,
|
|
149
|
+
TAccountRewardState extends string = string,
|
|
150
|
+
TAccountUserStakePosition extends string = string,
|
|
151
|
+
TAccountUserRewardDebt extends string = string,
|
|
152
|
+
> = {
|
|
153
|
+
user: Address<TAccountUser>;
|
|
154
|
+
payer: TransactionSigner<TAccountPayer>;
|
|
155
|
+
stakingMint: Address<TAccountStakingMint>;
|
|
156
|
+
rewardMint: Address<TAccountRewardMint>;
|
|
157
|
+
stakingConfig?: Address<TAccountStakingConfig>;
|
|
158
|
+
rewardState?: Address<TAccountRewardState>;
|
|
159
|
+
userStakePosition?: Address<TAccountUserStakePosition>;
|
|
160
|
+
userRewardDebt?: Address<TAccountUserRewardDebt>;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export async function getCreateUserRewardDebtInstructionAsync<
|
|
164
|
+
TAccountUser extends string,
|
|
165
|
+
TAccountPayer extends string,
|
|
166
|
+
TAccountStakingMint extends string,
|
|
167
|
+
TAccountRewardMint extends string,
|
|
168
|
+
TAccountStakingConfig extends string,
|
|
169
|
+
TAccountRewardState extends string,
|
|
170
|
+
TAccountUserStakePosition extends string,
|
|
171
|
+
TAccountUserRewardDebt extends string,
|
|
172
|
+
>(
|
|
173
|
+
input: CreateUserRewardDebtAsyncInput<
|
|
174
|
+
TAccountUser,
|
|
175
|
+
TAccountPayer,
|
|
176
|
+
TAccountStakingMint,
|
|
177
|
+
TAccountRewardMint,
|
|
178
|
+
TAccountStakingConfig,
|
|
179
|
+
TAccountRewardState,
|
|
180
|
+
TAccountUserStakePosition,
|
|
181
|
+
TAccountUserRewardDebt
|
|
182
|
+
>,
|
|
183
|
+
): Promise<
|
|
184
|
+
CreateUserRewardDebtInstruction<
|
|
185
|
+
typeof SEND_NEXUS_PROGRAM_ADDRESS,
|
|
186
|
+
TAccountUser,
|
|
187
|
+
TAccountPayer,
|
|
188
|
+
TAccountStakingMint,
|
|
189
|
+
TAccountRewardMint,
|
|
190
|
+
TAccountStakingConfig,
|
|
191
|
+
TAccountRewardState,
|
|
192
|
+
TAccountUserStakePosition,
|
|
193
|
+
TAccountUserRewardDebt,
|
|
194
|
+
'11111111111111111111111111111111'
|
|
195
|
+
>
|
|
196
|
+
> {
|
|
197
|
+
// Program address.
|
|
198
|
+
const programAddress = SEND_NEXUS_PROGRAM_ADDRESS;
|
|
199
|
+
|
|
200
|
+
// Original accounts.
|
|
201
|
+
const originalAccounts = {
|
|
202
|
+
user: { value: input.user ?? null, isWritable: false },
|
|
203
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
204
|
+
stakingMint: { value: input.stakingMint ?? null, isWritable: false },
|
|
205
|
+
rewardMint: { value: input.rewardMint ?? null, isWritable: false },
|
|
206
|
+
stakingConfig: {
|
|
207
|
+
value: input.stakingConfig ?? null,
|
|
208
|
+
isWritable: false,
|
|
209
|
+
},
|
|
210
|
+
rewardState: { value: input.rewardState ?? null, isWritable: false },
|
|
211
|
+
userStakePosition: {
|
|
212
|
+
value: input.userStakePosition ?? null,
|
|
213
|
+
isWritable: true,
|
|
214
|
+
},
|
|
215
|
+
userRewardDebt: {
|
|
216
|
+
value: input.userRewardDebt ?? null,
|
|
217
|
+
isWritable: true,
|
|
218
|
+
},
|
|
219
|
+
systemProgram: { value: null, isWritable: false },
|
|
220
|
+
};
|
|
221
|
+
const accounts = originalAccounts as Record<
|
|
222
|
+
keyof typeof originalAccounts,
|
|
223
|
+
ResolvedInstructionAccount
|
|
224
|
+
>;
|
|
225
|
+
|
|
226
|
+
// Resolve default values.
|
|
227
|
+
if (!accounts.stakingConfig.value) {
|
|
228
|
+
accounts.stakingConfig.value = STAKING_CONFIG_PDA_ADDRESS;
|
|
229
|
+
}
|
|
230
|
+
if (!accounts.rewardState.value) {
|
|
231
|
+
accounts.rewardState.value = await findRewardStatePda({
|
|
232
|
+
stakingConfig: getAddressFromResolvedInstructionAccount(
|
|
233
|
+
'stakingConfig',
|
|
234
|
+
accounts.stakingConfig.value,
|
|
235
|
+
),
|
|
236
|
+
rewardMint: getAddressFromResolvedInstructionAccount(
|
|
237
|
+
'rewardMint',
|
|
238
|
+
accounts.rewardMint.value,
|
|
239
|
+
),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (!accounts.userStakePosition.value) {
|
|
243
|
+
accounts.userStakePosition.value = await findUserStakePositionPda({
|
|
244
|
+
user: getAddressFromResolvedInstructionAccount(
|
|
245
|
+
'user',
|
|
246
|
+
accounts.user.value,
|
|
247
|
+
),
|
|
248
|
+
stakingMint: getAddressFromResolvedInstructionAccount(
|
|
249
|
+
'stakingMint',
|
|
250
|
+
accounts.stakingMint.value,
|
|
251
|
+
),
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (!accounts.userRewardDebt.value) {
|
|
255
|
+
accounts.userRewardDebt.value = await findUserRewardDebtPda({
|
|
256
|
+
user: getAddressFromResolvedInstructionAccount(
|
|
257
|
+
'user',
|
|
258
|
+
accounts.user.value,
|
|
259
|
+
),
|
|
260
|
+
stakingMint: getAddressFromResolvedInstructionAccount(
|
|
261
|
+
'stakingMint',
|
|
262
|
+
accounts.stakingMint.value,
|
|
263
|
+
),
|
|
264
|
+
rewardMint: getAddressFromResolvedInstructionAccount(
|
|
265
|
+
'rewardMint',
|
|
266
|
+
accounts.rewardMint.value,
|
|
267
|
+
),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (!accounts.systemProgram.value) {
|
|
271
|
+
accounts.systemProgram.value =
|
|
272
|
+
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
276
|
+
return Object.freeze({
|
|
277
|
+
accounts: [
|
|
278
|
+
getAccountMeta('user', accounts.user),
|
|
279
|
+
getAccountMeta('payer', accounts.payer),
|
|
280
|
+
getAccountMeta('stakingMint', accounts.stakingMint),
|
|
281
|
+
getAccountMeta('rewardMint', accounts.rewardMint),
|
|
282
|
+
getAccountMeta('stakingConfig', accounts.stakingConfig),
|
|
283
|
+
getAccountMeta('rewardState', accounts.rewardState),
|
|
284
|
+
getAccountMeta('userStakePosition', accounts.userStakePosition),
|
|
285
|
+
getAccountMeta('userRewardDebt', accounts.userRewardDebt),
|
|
286
|
+
getAccountMeta('systemProgram', accounts.systemProgram),
|
|
287
|
+
],
|
|
288
|
+
data: getCreateUserRewardDebtInstructionDataEncoder().encode({}),
|
|
289
|
+
programAddress,
|
|
290
|
+
} as CreateUserRewardDebtInstruction<
|
|
291
|
+
typeof SEND_NEXUS_PROGRAM_ADDRESS,
|
|
292
|
+
TAccountUser,
|
|
293
|
+
TAccountPayer,
|
|
294
|
+
TAccountStakingMint,
|
|
295
|
+
TAccountRewardMint,
|
|
296
|
+
TAccountStakingConfig,
|
|
297
|
+
TAccountRewardState,
|
|
298
|
+
TAccountUserStakePosition,
|
|
299
|
+
TAccountUserRewardDebt,
|
|
300
|
+
'11111111111111111111111111111111'
|
|
301
|
+
>);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export type CreateUserRewardDebtInput<
|
|
305
|
+
TAccountUser extends string = string,
|
|
306
|
+
TAccountPayer extends string = string,
|
|
307
|
+
TAccountStakingMint extends string = string,
|
|
308
|
+
TAccountRewardMint extends string = string,
|
|
309
|
+
TAccountStakingConfig extends string = string,
|
|
310
|
+
TAccountRewardState extends string = string,
|
|
311
|
+
TAccountUserStakePosition extends string = string,
|
|
312
|
+
TAccountUserRewardDebt extends string = string,
|
|
313
|
+
> = {
|
|
314
|
+
user: Address<TAccountUser>;
|
|
315
|
+
payer: TransactionSigner<TAccountPayer>;
|
|
316
|
+
stakingMint: Address<TAccountStakingMint>;
|
|
317
|
+
rewardMint: Address<TAccountRewardMint>;
|
|
318
|
+
stakingConfig?: Address<TAccountStakingConfig>;
|
|
319
|
+
rewardState: Address<TAccountRewardState>;
|
|
320
|
+
userStakePosition: Address<TAccountUserStakePosition>;
|
|
321
|
+
userRewardDebt: Address<TAccountUserRewardDebt>;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export function getCreateUserRewardDebtInstruction<
|
|
325
|
+
TAccountUser extends string,
|
|
326
|
+
TAccountPayer extends string,
|
|
327
|
+
TAccountStakingMint extends string,
|
|
328
|
+
TAccountRewardMint extends string,
|
|
329
|
+
TAccountStakingConfig extends string,
|
|
330
|
+
TAccountRewardState extends string,
|
|
331
|
+
TAccountUserStakePosition extends string,
|
|
332
|
+
TAccountUserRewardDebt extends string,
|
|
333
|
+
>(
|
|
334
|
+
input: CreateUserRewardDebtInput<
|
|
335
|
+
TAccountUser,
|
|
336
|
+
TAccountPayer,
|
|
337
|
+
TAccountStakingMint,
|
|
338
|
+
TAccountRewardMint,
|
|
339
|
+
TAccountStakingConfig,
|
|
340
|
+
TAccountRewardState,
|
|
341
|
+
TAccountUserStakePosition,
|
|
342
|
+
TAccountUserRewardDebt
|
|
343
|
+
>,
|
|
344
|
+
): CreateUserRewardDebtInstruction<
|
|
345
|
+
typeof SEND_NEXUS_PROGRAM_ADDRESS,
|
|
346
|
+
TAccountUser,
|
|
347
|
+
TAccountPayer,
|
|
348
|
+
TAccountStakingMint,
|
|
349
|
+
TAccountRewardMint,
|
|
350
|
+
TAccountStakingConfig,
|
|
351
|
+
TAccountRewardState,
|
|
352
|
+
TAccountUserStakePosition,
|
|
353
|
+
TAccountUserRewardDebt,
|
|
354
|
+
'11111111111111111111111111111111'
|
|
355
|
+
> {
|
|
356
|
+
// Program address.
|
|
357
|
+
const programAddress = SEND_NEXUS_PROGRAM_ADDRESS;
|
|
358
|
+
|
|
359
|
+
// Original accounts.
|
|
360
|
+
const originalAccounts = {
|
|
361
|
+
user: { value: input.user ?? null, isWritable: false },
|
|
362
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
363
|
+
stakingMint: { value: input.stakingMint ?? null, isWritable: false },
|
|
364
|
+
rewardMint: { value: input.rewardMint ?? null, isWritable: false },
|
|
365
|
+
stakingConfig: {
|
|
366
|
+
value: input.stakingConfig ?? null,
|
|
367
|
+
isWritable: false,
|
|
368
|
+
},
|
|
369
|
+
rewardState: { value: input.rewardState ?? null, isWritable: false },
|
|
370
|
+
userStakePosition: {
|
|
371
|
+
value: input.userStakePosition ?? null,
|
|
372
|
+
isWritable: true,
|
|
373
|
+
},
|
|
374
|
+
userRewardDebt: {
|
|
375
|
+
value: input.userRewardDebt ?? null,
|
|
376
|
+
isWritable: true,
|
|
377
|
+
},
|
|
378
|
+
systemProgram: { value: null, isWritable: false },
|
|
379
|
+
};
|
|
380
|
+
const accounts = originalAccounts as Record<
|
|
381
|
+
keyof typeof originalAccounts,
|
|
382
|
+
ResolvedInstructionAccount
|
|
383
|
+
>;
|
|
384
|
+
|
|
385
|
+
// Resolve default values.
|
|
386
|
+
if (!accounts.stakingConfig.value) {
|
|
387
|
+
accounts.stakingConfig.value = STAKING_CONFIG_PDA_ADDRESS;
|
|
388
|
+
}
|
|
389
|
+
if (!accounts.systemProgram.value) {
|
|
390
|
+
accounts.systemProgram.value =
|
|
391
|
+
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
395
|
+
return Object.freeze({
|
|
396
|
+
accounts: [
|
|
397
|
+
getAccountMeta('user', accounts.user),
|
|
398
|
+
getAccountMeta('payer', accounts.payer),
|
|
399
|
+
getAccountMeta('stakingMint', accounts.stakingMint),
|
|
400
|
+
getAccountMeta('rewardMint', accounts.rewardMint),
|
|
401
|
+
getAccountMeta('stakingConfig', accounts.stakingConfig),
|
|
402
|
+
getAccountMeta('rewardState', accounts.rewardState),
|
|
403
|
+
getAccountMeta('userStakePosition', accounts.userStakePosition),
|
|
404
|
+
getAccountMeta('userRewardDebt', accounts.userRewardDebt),
|
|
405
|
+
getAccountMeta('systemProgram', accounts.systemProgram),
|
|
406
|
+
],
|
|
407
|
+
data: getCreateUserRewardDebtInstructionDataEncoder().encode({}),
|
|
408
|
+
programAddress,
|
|
409
|
+
} as CreateUserRewardDebtInstruction<
|
|
410
|
+
typeof SEND_NEXUS_PROGRAM_ADDRESS,
|
|
411
|
+
TAccountUser,
|
|
412
|
+
TAccountPayer,
|
|
413
|
+
TAccountStakingMint,
|
|
414
|
+
TAccountRewardMint,
|
|
415
|
+
TAccountStakingConfig,
|
|
416
|
+
TAccountRewardState,
|
|
417
|
+
TAccountUserStakePosition,
|
|
418
|
+
TAccountUserRewardDebt,
|
|
419
|
+
'11111111111111111111111111111111'
|
|
420
|
+
>);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export type ParsedCreateUserRewardDebtInstruction<
|
|
424
|
+
TProgram extends string = typeof SEND_NEXUS_PROGRAM_ADDRESS,
|
|
425
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
426
|
+
> = {
|
|
427
|
+
programAddress: Address<TProgram>;
|
|
428
|
+
accounts: {
|
|
429
|
+
user: TAccountMetas[0];
|
|
430
|
+
payer: TAccountMetas[1];
|
|
431
|
+
stakingMint: TAccountMetas[2];
|
|
432
|
+
rewardMint: TAccountMetas[3];
|
|
433
|
+
stakingConfig: TAccountMetas[4];
|
|
434
|
+
rewardState: TAccountMetas[5];
|
|
435
|
+
userStakePosition: TAccountMetas[6];
|
|
436
|
+
userRewardDebt: TAccountMetas[7];
|
|
437
|
+
systemProgram: TAccountMetas[8];
|
|
438
|
+
};
|
|
439
|
+
data: CreateUserRewardDebtInstructionData;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export function parseCreateUserRewardDebtInstruction<
|
|
443
|
+
TProgram extends string,
|
|
444
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
445
|
+
>(
|
|
446
|
+
instruction: Instruction<TProgram> &
|
|
447
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
448
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
449
|
+
): ParsedCreateUserRewardDebtInstruction<TProgram, TAccountMetas> {
|
|
450
|
+
assertIsInstructionForProgram(instruction, SEND_NEXUS_PROGRAM_ADDRESS);
|
|
451
|
+
if (
|
|
452
|
+
!containsBytes(
|
|
453
|
+
instruction.data,
|
|
454
|
+
CREATE_USER_REWARD_DEBT_DISCRIMINATOR,
|
|
455
|
+
0,
|
|
456
|
+
)
|
|
457
|
+
) {
|
|
458
|
+
const error = new Error(
|
|
459
|
+
`parseCreateUserRewardDebtInstruction: instruction data does not match the CreateUserRewardDebt discriminator`,
|
|
460
|
+
);
|
|
461
|
+
error.name = 'InstructionDiscriminatorMismatchError';
|
|
462
|
+
throw error;
|
|
463
|
+
}
|
|
464
|
+
if (instruction.accounts.length < 9) {
|
|
465
|
+
throw new SolanaError(
|
|
466
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
467
|
+
{
|
|
468
|
+
actualAccountMetas: instruction.accounts.length,
|
|
469
|
+
expectedAccountMetas: 9,
|
|
470
|
+
},
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
let accountIndex = 0;
|
|
474
|
+
const getNextAccount = () => {
|
|
475
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[
|
|
476
|
+
accountIndex
|
|
477
|
+
]!;
|
|
478
|
+
accountIndex += 1;
|
|
479
|
+
return accountMeta;
|
|
480
|
+
};
|
|
481
|
+
return {
|
|
482
|
+
programAddress: instruction.programAddress,
|
|
483
|
+
accounts: {
|
|
484
|
+
user: getNextAccount(),
|
|
485
|
+
payer: getNextAccount(),
|
|
486
|
+
stakingMint: getNextAccount(),
|
|
487
|
+
rewardMint: getNextAccount(),
|
|
488
|
+
stakingConfig: getNextAccount(),
|
|
489
|
+
rewardState: getNextAccount(),
|
|
490
|
+
userStakePosition: getNextAccount(),
|
|
491
|
+
userRewardDebt: getNextAccount(),
|
|
492
|
+
systemProgram: getNextAccount(),
|
|
493
|
+
},
|
|
494
|
+
data: getCreateUserRewardDebtInstructionDataDecoder().decode(
|
|
495
|
+
instruction.data,
|
|
496
|
+
),
|
|
497
|
+
};
|
|
498
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export * from './claim.js';
|
|
10
|
+
export * from './createUserRewardDebt.js';
|
|
11
|
+
export * from './sendNexus.instructions.js';
|
|
12
|
+
export * from './settle.js';
|
|
13
|
+
export * from './stake.js';
|
|
14
|
+
export * from './unstake.js';
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
assertIsInstructionWithAccounts,
|
|
11
|
+
containsBytes,
|
|
12
|
+
type Address,
|
|
13
|
+
type Instruction,
|
|
14
|
+
type InstructionWithData,
|
|
15
|
+
type ReadonlyUint8Array,
|
|
16
|
+
} from '@solana/kit';
|
|
17
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
18
|
+
import {
|
|
19
|
+
CLAIM_DISCRIMINATOR,
|
|
20
|
+
parseClaimInstruction,
|
|
21
|
+
type ParsedClaimInstruction,
|
|
22
|
+
} from './claim.js';
|
|
23
|
+
import {
|
|
24
|
+
CREATE_USER_REWARD_DEBT_DISCRIMINATOR,
|
|
25
|
+
parseCreateUserRewardDebtInstruction,
|
|
26
|
+
type ParsedCreateUserRewardDebtInstruction,
|
|
27
|
+
} from './createUserRewardDebt.js';
|
|
28
|
+
import {
|
|
29
|
+
parseSettleInstruction,
|
|
30
|
+
SETTLE_DISCRIMINATOR,
|
|
31
|
+
type ParsedSettleInstruction,
|
|
32
|
+
} from './settle.js';
|
|
33
|
+
import {
|
|
34
|
+
parseStakeInstruction,
|
|
35
|
+
STAKE_DISCRIMINATOR,
|
|
36
|
+
type ParsedStakeInstruction,
|
|
37
|
+
} from './stake.js';
|
|
38
|
+
import {
|
|
39
|
+
parseUnstakeInstruction,
|
|
40
|
+
type ParsedUnstakeInstruction,
|
|
41
|
+
UNSTAKE_DISCRIMINATOR,
|
|
42
|
+
} from './unstake.js';
|
|
43
|
+
|
|
44
|
+
/** Instruction kinds of the sendNexus program. */
|
|
45
|
+
export type SendNexusInstructionType =
|
|
46
|
+
| 'claim'
|
|
47
|
+
| 'createUserRewardDebt'
|
|
48
|
+
| 'settle'
|
|
49
|
+
| 'stake'
|
|
50
|
+
| 'unstake';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Identifies sendNexus instruction data by its discriminators.
|
|
54
|
+
* Returns `null` when the instruction is for another program or the data matches no known instruction.
|
|
55
|
+
*/
|
|
56
|
+
export function identifySendNexusInstruction(
|
|
57
|
+
instruction:
|
|
58
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
59
|
+
| ReadonlyUint8Array,
|
|
60
|
+
): SendNexusInstructionType | null {
|
|
61
|
+
if (
|
|
62
|
+
'data' in instruction &&
|
|
63
|
+
instruction.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS
|
|
64
|
+
)
|
|
65
|
+
return null;
|
|
66
|
+
const data = 'data' in instruction ? instruction.data : instruction;
|
|
67
|
+
if (containsBytes(data, CLAIM_DISCRIMINATOR, 0)) {
|
|
68
|
+
return 'claim';
|
|
69
|
+
}
|
|
70
|
+
if (containsBytes(data, CREATE_USER_REWARD_DEBT_DISCRIMINATOR, 0)) {
|
|
71
|
+
return 'createUserRewardDebt';
|
|
72
|
+
}
|
|
73
|
+
if (containsBytes(data, SETTLE_DISCRIMINATOR, 0)) {
|
|
74
|
+
return 'settle';
|
|
75
|
+
}
|
|
76
|
+
if (containsBytes(data, STAKE_DISCRIMINATOR, 0)) {
|
|
77
|
+
return 'stake';
|
|
78
|
+
}
|
|
79
|
+
if (containsBytes(data, UNSTAKE_DISCRIMINATOR, 0)) {
|
|
80
|
+
return 'unstake';
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Parsed sendNexus instruction: the instruction kind tag plus its parsed accounts and data. */
|
|
86
|
+
export type ParsedSendNexusInstruction<
|
|
87
|
+
TProgram extends string = '7rrCurqdWFesbzwtYPo95fM8waTtVXgXwCom45x1sfNX',
|
|
88
|
+
> =
|
|
89
|
+
| ({ instructionType: 'claim' } & ParsedClaimInstruction<TProgram>)
|
|
90
|
+
| ({
|
|
91
|
+
instructionType: 'createUserRewardDebt';
|
|
92
|
+
} & ParsedCreateUserRewardDebtInstruction<TProgram>)
|
|
93
|
+
| ({ instructionType: 'settle' } & ParsedSettleInstruction<TProgram>)
|
|
94
|
+
| ({ instructionType: 'stake' } & ParsedStakeInstruction<TProgram>)
|
|
95
|
+
| ({ instructionType: 'unstake' } & ParsedUnstakeInstruction<TProgram>);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Parses a sendNexus instruction into its kind tag plus parsed accounts and data.
|
|
99
|
+
* Returns `null` when the instruction is for another program or no known instruction matches;
|
|
100
|
+
* throws if a matched instruction fails to parse.
|
|
101
|
+
*/
|
|
102
|
+
export function parseSendNexusInstruction<TProgram extends string>(
|
|
103
|
+
instruction: Instruction<TProgram> &
|
|
104
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
105
|
+
): ParsedSendNexusInstruction<TProgram> | null {
|
|
106
|
+
if (instruction.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) return null;
|
|
107
|
+
const instructionType = identifySendNexusInstruction(instruction);
|
|
108
|
+
if (instructionType === null) return null;
|
|
109
|
+
switch (instructionType) {
|
|
110
|
+
case 'claim': {
|
|
111
|
+
assertIsInstructionWithAccounts(instruction);
|
|
112
|
+
return {
|
|
113
|
+
instructionType: 'claim',
|
|
114
|
+
...parseClaimInstruction(instruction),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
case 'createUserRewardDebt': {
|
|
118
|
+
assertIsInstructionWithAccounts(instruction);
|
|
119
|
+
return {
|
|
120
|
+
instructionType: 'createUserRewardDebt',
|
|
121
|
+
...parseCreateUserRewardDebtInstruction(instruction),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
case 'settle': {
|
|
125
|
+
assertIsInstructionWithAccounts(instruction);
|
|
126
|
+
return {
|
|
127
|
+
instructionType: 'settle',
|
|
128
|
+
...parseSettleInstruction(instruction),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
case 'stake': {
|
|
132
|
+
assertIsInstructionWithAccounts(instruction);
|
|
133
|
+
return {
|
|
134
|
+
instructionType: 'stake',
|
|
135
|
+
...parseStakeInstruction(instruction),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
case 'unstake': {
|
|
139
|
+
assertIsInstructionWithAccounts(instruction);
|
|
140
|
+
return {
|
|
141
|
+
instructionType: 'unstake',
|
|
142
|
+
...parseUnstakeInstruction(instruction),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|