@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,218 @@
|
|
|
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
|
+
assertAccountExists,
|
|
11
|
+
assertAccountsExist,
|
|
12
|
+
combineCodec,
|
|
13
|
+
containsBytes,
|
|
14
|
+
decodeAccount,
|
|
15
|
+
fetchEncodedAccount,
|
|
16
|
+
fetchEncodedAccounts,
|
|
17
|
+
fixDecoderSize,
|
|
18
|
+
fixEncoderSize,
|
|
19
|
+
getAddressDecoder,
|
|
20
|
+
getAddressEncoder,
|
|
21
|
+
getBytesDecoder,
|
|
22
|
+
getBytesEncoder,
|
|
23
|
+
getStructDecoder,
|
|
24
|
+
getStructEncoder,
|
|
25
|
+
getU16Decoder,
|
|
26
|
+
getU16Encoder,
|
|
27
|
+
getU32Decoder,
|
|
28
|
+
getU32Encoder,
|
|
29
|
+
getU64Decoder,
|
|
30
|
+
getU64Encoder,
|
|
31
|
+
getU8Decoder,
|
|
32
|
+
getU8Encoder,
|
|
33
|
+
transformEncoder,
|
|
34
|
+
type Account,
|
|
35
|
+
type Address,
|
|
36
|
+
type EncodedAccount,
|
|
37
|
+
type FetchAccountConfig,
|
|
38
|
+
type FetchAccountsConfig,
|
|
39
|
+
type FixedSizeCodec,
|
|
40
|
+
type FixedSizeDecoder,
|
|
41
|
+
type FixedSizeEncoder,
|
|
42
|
+
type MaybeAccount,
|
|
43
|
+
type MaybeEncodedAccount,
|
|
44
|
+
type ReadonlyUint8Array,
|
|
45
|
+
} from '@solana/kit';
|
|
46
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
47
|
+
|
|
48
|
+
export const USER_STAKE_POSITION_DISCRIMINATOR: ReadonlyUint8Array =
|
|
49
|
+
new Uint8Array([123, 46, 248, 17, 240, 135, 201, 17]);
|
|
50
|
+
|
|
51
|
+
export function getUserStakePositionDiscriminatorBytes(): ReadonlyUint8Array {
|
|
52
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
53
|
+
USER_STAKE_POSITION_DISCRIMINATOR,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type UserStakePosition = {
|
|
58
|
+
discriminator: ReadonlyUint8Array;
|
|
59
|
+
version: number;
|
|
60
|
+
bump: number;
|
|
61
|
+
user: Address;
|
|
62
|
+
stakingMint: Address;
|
|
63
|
+
amount: bigint;
|
|
64
|
+
stakeVersion: number;
|
|
65
|
+
settledCount: number;
|
|
66
|
+
reserved: ReadonlyUint8Array;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type UserStakePositionArgs = {
|
|
70
|
+
version: number;
|
|
71
|
+
bump: number;
|
|
72
|
+
user: Address;
|
|
73
|
+
stakingMint: Address;
|
|
74
|
+
amount: number | bigint;
|
|
75
|
+
stakeVersion: number;
|
|
76
|
+
settledCount: number;
|
|
77
|
+
reserved: ReadonlyUint8Array;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** Gets the encoder for {@link UserStakePositionArgs} account data. */
|
|
81
|
+
export function getUserStakePositionEncoder(): FixedSizeEncoder<UserStakePositionArgs> {
|
|
82
|
+
return transformEncoder(
|
|
83
|
+
getStructEncoder([
|
|
84
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
85
|
+
['version', getU8Encoder()],
|
|
86
|
+
['bump', getU8Encoder()],
|
|
87
|
+
['user', getAddressEncoder()],
|
|
88
|
+
['stakingMint', getAddressEncoder()],
|
|
89
|
+
['amount', getU64Encoder()],
|
|
90
|
+
['stakeVersion', getU32Encoder()],
|
|
91
|
+
['settledCount', getU16Encoder()],
|
|
92
|
+
['reserved', fixEncoderSize(getBytesEncoder(), 32)],
|
|
93
|
+
]),
|
|
94
|
+
(value) => ({
|
|
95
|
+
...value,
|
|
96
|
+
discriminator: USER_STAKE_POSITION_DISCRIMINATOR,
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Gets the decoder for {@link UserStakePosition} account data. */
|
|
102
|
+
export function getUserStakePositionDecoder(): FixedSizeDecoder<UserStakePosition> {
|
|
103
|
+
return getStructDecoder([
|
|
104
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
105
|
+
['version', getU8Decoder()],
|
|
106
|
+
['bump', getU8Decoder()],
|
|
107
|
+
['user', getAddressDecoder()],
|
|
108
|
+
['stakingMint', getAddressDecoder()],
|
|
109
|
+
['amount', getU64Decoder()],
|
|
110
|
+
['stakeVersion', getU32Decoder()],
|
|
111
|
+
['settledCount', getU16Decoder()],
|
|
112
|
+
['reserved', fixDecoderSize(getBytesDecoder(), 32)],
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Gets the codec for {@link UserStakePosition} account data. */
|
|
117
|
+
export function getUserStakePositionCodec(): FixedSizeCodec<
|
|
118
|
+
UserStakePositionArgs,
|
|
119
|
+
UserStakePosition
|
|
120
|
+
> {
|
|
121
|
+
return combineCodec(
|
|
122
|
+
getUserStakePositionEncoder(),
|
|
123
|
+
getUserStakePositionDecoder(),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function decodeUserStakePosition<TAddress extends string = string>(
|
|
128
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
129
|
+
): Account<UserStakePosition, TAddress>;
|
|
130
|
+
export function decodeUserStakePosition<TAddress extends string = string>(
|
|
131
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
132
|
+
): MaybeAccount<UserStakePosition, TAddress>;
|
|
133
|
+
export function decodeUserStakePosition<TAddress extends string = string>(
|
|
134
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
135
|
+
):
|
|
136
|
+
| Account<UserStakePosition, TAddress>
|
|
137
|
+
| MaybeAccount<UserStakePosition, TAddress> {
|
|
138
|
+
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
139
|
+
if (encodedAccount.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) {
|
|
140
|
+
const error = new Error(
|
|
141
|
+
`decodeUserStakePosition: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_NEXUS_PROGRAM_ADDRESS}`,
|
|
142
|
+
);
|
|
143
|
+
error.name = 'AccountOwnerMismatchError';
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
if (
|
|
147
|
+
!containsBytes(
|
|
148
|
+
encodedAccount.data,
|
|
149
|
+
USER_STAKE_POSITION_DISCRIMINATOR,
|
|
150
|
+
0,
|
|
151
|
+
)
|
|
152
|
+
) {
|
|
153
|
+
const error = new Error(
|
|
154
|
+
`decodeUserStakePosition: account ${encodedAccount.address} does not match the UserStakePosition discriminator`,
|
|
155
|
+
);
|
|
156
|
+
error.name = 'AccountDiscriminatorMismatchError';
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return decodeAccount(
|
|
161
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
162
|
+
getUserStakePositionDecoder(),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function fetchUserStakePosition<TAddress extends string = string>(
|
|
167
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
168
|
+
address: Address<TAddress>,
|
|
169
|
+
config?: FetchAccountConfig,
|
|
170
|
+
): Promise<Account<UserStakePosition, TAddress>> {
|
|
171
|
+
const maybeAccount = await fetchMaybeUserStakePosition(
|
|
172
|
+
rpc,
|
|
173
|
+
address,
|
|
174
|
+
config,
|
|
175
|
+
);
|
|
176
|
+
assertAccountExists(maybeAccount);
|
|
177
|
+
return maybeAccount;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function fetchMaybeUserStakePosition<
|
|
181
|
+
TAddress extends string = string,
|
|
182
|
+
>(
|
|
183
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
184
|
+
address: Address<TAddress>,
|
|
185
|
+
config?: FetchAccountConfig,
|
|
186
|
+
): Promise<MaybeAccount<UserStakePosition, TAddress>> {
|
|
187
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
188
|
+
return decodeUserStakePosition(maybeAccount);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function fetchAllUserStakePosition(
|
|
192
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
193
|
+
addresses: Array<Address>,
|
|
194
|
+
config?: FetchAccountsConfig,
|
|
195
|
+
): Promise<Account<UserStakePosition>[]> {
|
|
196
|
+
const maybeAccounts = await fetchAllMaybeUserStakePosition(
|
|
197
|
+
rpc,
|
|
198
|
+
addresses,
|
|
199
|
+
config,
|
|
200
|
+
);
|
|
201
|
+
assertAccountsExist(maybeAccounts);
|
|
202
|
+
return maybeAccounts;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function fetchAllMaybeUserStakePosition(
|
|
206
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
207
|
+
addresses: Array<Address>,
|
|
208
|
+
config?: FetchAccountsConfig,
|
|
209
|
+
): Promise<MaybeAccount<UserStakePosition>[]> {
|
|
210
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
211
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
212
|
+
decodeUserStakePosition(maybeAccount),
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function getUserStakePositionSize(): number {
|
|
217
|
+
return 120;
|
|
218
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { address, type Address } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_PARTNER: Address = address(
|
|
12
|
+
'11111111111111111111111111111111',
|
|
13
|
+
);
|
|
@@ -0,0 +1,229 @@
|
|
|
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
|
+
isProgramError,
|
|
11
|
+
type Address,
|
|
12
|
+
type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
|
|
13
|
+
type SolanaError,
|
|
14
|
+
} from '@solana/kit';
|
|
15
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
16
|
+
|
|
17
|
+
/** InsufficientStake: Insufficient stake balance */
|
|
18
|
+
export const SEND_NEXUS_ERROR__INSUFFICIENT_STAKE = 0x1770; // 6000
|
|
19
|
+
/** InvalidRewardMint: Invalid reward mint */
|
|
20
|
+
export const SEND_NEXUS_ERROR__INVALID_REWARD_MINT = 0x1771; // 6001
|
|
21
|
+
/** InvalidVault: Invalid vault */
|
|
22
|
+
export const SEND_NEXUS_ERROR__INVALID_VAULT = 0x1772; // 6002
|
|
23
|
+
/** StakingAlreadyEnabled: Staking already enabled */
|
|
24
|
+
export const SEND_NEXUS_ERROR__STAKING_ALREADY_ENABLED = 0x1775; // 6005
|
|
25
|
+
/** StakingNotEnabled: Staking not enabled */
|
|
26
|
+
export const SEND_NEXUS_ERROR__STAKING_NOT_ENABLED = 0x1776; // 6006
|
|
27
|
+
/** InvalidStakingMint: Invalid staking mint */
|
|
28
|
+
export const SEND_NEXUS_ERROR__INVALID_STAKING_MINT = 0x1777; // 6007
|
|
29
|
+
/** InvalidRewardState: Invalid reward state */
|
|
30
|
+
export const SEND_NEXUS_ERROR__INVALID_REWARD_STATE = 0x1778; // 6008
|
|
31
|
+
/** InvalidMint: Invalid mint */
|
|
32
|
+
export const SEND_NEXUS_ERROR__INVALID_MINT = 0x1779; // 6009
|
|
33
|
+
/** InvalidDestination: Invalid destination account */
|
|
34
|
+
export const SEND_NEXUS_ERROR__INVALID_DESTINATION = 0x177a; // 6010
|
|
35
|
+
/** StakingMintAlreadyBound: Staking mint already bound */
|
|
36
|
+
export const SEND_NEXUS_ERROR__STAKING_MINT_ALREADY_BOUND = 0x177b; // 6011
|
|
37
|
+
/** InvalidFeePreset: Invalid fee configuration */
|
|
38
|
+
export const SEND_NEXUS_ERROR__INVALID_FEE_PRESET = 0x177c; // 6012
|
|
39
|
+
/** InvalidPresetIndex: Invalid preset index */
|
|
40
|
+
export const SEND_NEXUS_ERROR__INVALID_PRESET_INDEX = 0x177d; // 6013
|
|
41
|
+
/** MissingFeeSource: Must provide either fee_preset or custom fees */
|
|
42
|
+
export const SEND_NEXUS_ERROR__MISSING_FEE_SOURCE = 0x177e; // 6014
|
|
43
|
+
/** AmbiguousFeeSource: Cannot specify both fee_preset and custom_fees */
|
|
44
|
+
export const SEND_NEXUS_ERROR__AMBIGUOUS_FEE_SOURCE = 0x177f; // 6015
|
|
45
|
+
/** InvalidPartnerName: Partner name cannot be empty */
|
|
46
|
+
export const SEND_NEXUS_ERROR__INVALID_PARTNER_NAME = 0x1780; // 6016
|
|
47
|
+
/** PartnerNotOnPreset: Partner account does not use this preset */
|
|
48
|
+
export const SEND_NEXUS_ERROR__PARTNER_NOT_ON_PRESET = 0x1781; // 6017
|
|
49
|
+
/** InvalidPartnerNote: Invalid partner note */
|
|
50
|
+
export const SEND_NEXUS_ERROR__INVALID_PARTNER_NOTE = 0x1782; // 6018
|
|
51
|
+
/** InvalidPresetName: Invalid preset name */
|
|
52
|
+
export const SEND_NEXUS_ERROR__INVALID_PRESET_NAME = 0x1783; // 6019
|
|
53
|
+
/** TooManyAuthPlatforms: Too many auth platforms (max 255) */
|
|
54
|
+
export const SEND_NEXUS_ERROR__TOO_MANY_AUTH_PLATFORMS = 0x1784; // 6020
|
|
55
|
+
/** InvalidAuthPlatformIndex: Invalid auth platform index */
|
|
56
|
+
export const SEND_NEXUS_ERROR__INVALID_AUTH_PLATFORM_INDEX = 0x1785; // 6021
|
|
57
|
+
/** InvalidAuthPlatformName: Invalid auth platform name */
|
|
58
|
+
export const SEND_NEXUS_ERROR__INVALID_AUTH_PLATFORM_NAME = 0x1786; // 6022
|
|
59
|
+
/** DuplicateAuthPlatformName: Duplicate auth platform name */
|
|
60
|
+
export const SEND_NEXUS_ERROR__DUPLICATE_AUTH_PLATFORM_NAME = 0x1787; // 6023
|
|
61
|
+
/** InvalidAuthority: Invalid authority */
|
|
62
|
+
export const SEND_NEXUS_ERROR__INVALID_AUTHORITY = 0x1788; // 6024
|
|
63
|
+
/** ReservedPartner: Cannot add the default partner */
|
|
64
|
+
export const SEND_NEXUS_ERROR__RESERVED_PARTNER = 0x1789; // 6025
|
|
65
|
+
/** InvalidRewardAccrual: Invalid reward accrual */
|
|
66
|
+
export const SEND_NEXUS_ERROR__INVALID_REWARD_ACCRUAL = 0x178a; // 6026
|
|
67
|
+
/** RewardsNotSettled: Settle every reward mint before staking or unstaking - call settle for each registered mint */
|
|
68
|
+
export const SEND_NEXUS_ERROR__REWARDS_NOT_SETTLED = 0x178b; // 6027
|
|
69
|
+
/** InvalidUsdcPrice: USDC price must be non-zero - 0 means no price */
|
|
70
|
+
export const SEND_NEXUS_ERROR__INVALID_USDC_PRICE = 0x178c; // 6028
|
|
71
|
+
/** InvalidPlatformConfig: Platform config cannot be the default address */
|
|
72
|
+
export const SEND_NEXUS_ERROR__INVALID_PLATFORM_CONFIG = 0x178d; // 6029
|
|
73
|
+
/** InvalidPartnerConfig: Partner config address does not match its stored seeds */
|
|
74
|
+
export const SEND_NEXUS_ERROR__INVALID_PARTNER_CONFIG = 0x178e; // 6030
|
|
75
|
+
/** PresetPlatformMismatch: Fee preset belongs to a different platform */
|
|
76
|
+
export const SEND_NEXUS_ERROR__PRESET_PLATFORM_MISMATCH = 0x178f; // 6031
|
|
77
|
+
/** ProgramPaused: Program is paused */
|
|
78
|
+
export const SEND_NEXUS_ERROR__PROGRAM_PAUSED = 0x1b58; // 7000
|
|
79
|
+
/** Unauthorized: Unauthorized */
|
|
80
|
+
export const SEND_NEXUS_ERROR__UNAUTHORIZED = 0x1b59; // 7001
|
|
81
|
+
/** ArithmeticOverflow: Arithmetic overflow */
|
|
82
|
+
export const SEND_NEXUS_ERROR__ARITHMETIC_OVERFLOW = 0x1b5a; // 7002
|
|
83
|
+
/** InvalidPythAccount: Invalid Pyth price account */
|
|
84
|
+
export const SEND_NEXUS_ERROR__INVALID_PYTH_ACCOUNT = 0x1b5b; // 7003
|
|
85
|
+
/** InvalidPythFeed: Invalid Pyth feed ID */
|
|
86
|
+
export const SEND_NEXUS_ERROR__INVALID_PYTH_FEED = 0x1b5c; // 7004
|
|
87
|
+
/** InvalidSlug: Invalid slug: must be non-empty, <= max_len bytes, lowercase alphanumeric or underscore */
|
|
88
|
+
export const SEND_NEXUS_ERROR__INVALID_SLUG = 0x1b5d; // 7005
|
|
89
|
+
/** TextTooLong: Text too long */
|
|
90
|
+
export const SEND_NEXUS_ERROR__TEXT_TOO_LONG = 0x1b5e; // 7006
|
|
91
|
+
/** UserTokenAccountWrongProgram: User token account owned by the wrong token program */
|
|
92
|
+
export const SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_PROGRAM = 0x1b5f; // 7007
|
|
93
|
+
/** UserTokenAccountInvalid: User token account is not an initialized token account */
|
|
94
|
+
export const SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_INVALID = 0x1b60; // 7008
|
|
95
|
+
/** UserTokenAccountWrongMint: User token account mint does not match the trade */
|
|
96
|
+
export const SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT = 0x1b61; // 7009
|
|
97
|
+
/** UserTokenAccountWrongAuthority: User token account is not owned by the trading user */
|
|
98
|
+
export const SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY = 0x1b62; // 7010
|
|
99
|
+
/** NothingToClaim: Nothing to claim */
|
|
100
|
+
export const SEND_NEXUS_ERROR__NOTHING_TO_CLAIM = 0x1b63; // 7011
|
|
101
|
+
/** InvalidCreatorId: Creator identity is not a decodable wallet address */
|
|
102
|
+
export const SEND_NEXUS_ERROR__INVALID_CREATOR_ID = 0x1b64; // 7012
|
|
103
|
+
/** QuoteMintPriceUnset: Quote mint has no USDC price on its nexus reward state */
|
|
104
|
+
export const SEND_NEXUS_ERROR__QUOTE_MINT_PRICE_UNSET = 0x1b65; // 7013
|
|
105
|
+
/** TransferFeeNotSettleable: Token-2022 transfer fee schedule cannot settle the exact amount */
|
|
106
|
+
export const SEND_NEXUS_ERROR__TRANSFER_FEE_NOT_SETTLEABLE = 0x1b66; // 7014
|
|
107
|
+
/** InsufficientLiquidity: Insufficient liquidity */
|
|
108
|
+
export const SEND_NEXUS_ERROR__INSUFFICIENT_LIQUIDITY = 0x1bbc; // 7100
|
|
109
|
+
/** InvalidAmount: Invalid amount */
|
|
110
|
+
export const SEND_NEXUS_ERROR__INVALID_AMOUNT = 0x1bbd; // 7101
|
|
111
|
+
|
|
112
|
+
export type SendNexusError =
|
|
113
|
+
| typeof SEND_NEXUS_ERROR__AMBIGUOUS_FEE_SOURCE
|
|
114
|
+
| typeof SEND_NEXUS_ERROR__ARITHMETIC_OVERFLOW
|
|
115
|
+
| typeof SEND_NEXUS_ERROR__DUPLICATE_AUTH_PLATFORM_NAME
|
|
116
|
+
| typeof SEND_NEXUS_ERROR__INSUFFICIENT_LIQUIDITY
|
|
117
|
+
| typeof SEND_NEXUS_ERROR__INSUFFICIENT_STAKE
|
|
118
|
+
| typeof SEND_NEXUS_ERROR__INVALID_AMOUNT
|
|
119
|
+
| typeof SEND_NEXUS_ERROR__INVALID_AUTHORITY
|
|
120
|
+
| typeof SEND_NEXUS_ERROR__INVALID_AUTH_PLATFORM_INDEX
|
|
121
|
+
| typeof SEND_NEXUS_ERROR__INVALID_AUTH_PLATFORM_NAME
|
|
122
|
+
| typeof SEND_NEXUS_ERROR__INVALID_CREATOR_ID
|
|
123
|
+
| typeof SEND_NEXUS_ERROR__INVALID_DESTINATION
|
|
124
|
+
| typeof SEND_NEXUS_ERROR__INVALID_FEE_PRESET
|
|
125
|
+
| typeof SEND_NEXUS_ERROR__INVALID_MINT
|
|
126
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PARTNER_CONFIG
|
|
127
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PARTNER_NAME
|
|
128
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PARTNER_NOTE
|
|
129
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PLATFORM_CONFIG
|
|
130
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PRESET_INDEX
|
|
131
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PRESET_NAME
|
|
132
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PYTH_ACCOUNT
|
|
133
|
+
| typeof SEND_NEXUS_ERROR__INVALID_PYTH_FEED
|
|
134
|
+
| typeof SEND_NEXUS_ERROR__INVALID_REWARD_ACCRUAL
|
|
135
|
+
| typeof SEND_NEXUS_ERROR__INVALID_REWARD_MINT
|
|
136
|
+
| typeof SEND_NEXUS_ERROR__INVALID_REWARD_STATE
|
|
137
|
+
| typeof SEND_NEXUS_ERROR__INVALID_SLUG
|
|
138
|
+
| typeof SEND_NEXUS_ERROR__INVALID_STAKING_MINT
|
|
139
|
+
| typeof SEND_NEXUS_ERROR__INVALID_USDC_PRICE
|
|
140
|
+
| typeof SEND_NEXUS_ERROR__INVALID_VAULT
|
|
141
|
+
| typeof SEND_NEXUS_ERROR__MISSING_FEE_SOURCE
|
|
142
|
+
| typeof SEND_NEXUS_ERROR__NOTHING_TO_CLAIM
|
|
143
|
+
| typeof SEND_NEXUS_ERROR__PARTNER_NOT_ON_PRESET
|
|
144
|
+
| typeof SEND_NEXUS_ERROR__PRESET_PLATFORM_MISMATCH
|
|
145
|
+
| typeof SEND_NEXUS_ERROR__PROGRAM_PAUSED
|
|
146
|
+
| typeof SEND_NEXUS_ERROR__QUOTE_MINT_PRICE_UNSET
|
|
147
|
+
| typeof SEND_NEXUS_ERROR__RESERVED_PARTNER
|
|
148
|
+
| typeof SEND_NEXUS_ERROR__REWARDS_NOT_SETTLED
|
|
149
|
+
| typeof SEND_NEXUS_ERROR__STAKING_ALREADY_ENABLED
|
|
150
|
+
| typeof SEND_NEXUS_ERROR__STAKING_MINT_ALREADY_BOUND
|
|
151
|
+
| typeof SEND_NEXUS_ERROR__STAKING_NOT_ENABLED
|
|
152
|
+
| typeof SEND_NEXUS_ERROR__TEXT_TOO_LONG
|
|
153
|
+
| typeof SEND_NEXUS_ERROR__TOO_MANY_AUTH_PLATFORMS
|
|
154
|
+
| typeof SEND_NEXUS_ERROR__TRANSFER_FEE_NOT_SETTLEABLE
|
|
155
|
+
| typeof SEND_NEXUS_ERROR__UNAUTHORIZED
|
|
156
|
+
| typeof SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_INVALID
|
|
157
|
+
| typeof SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY
|
|
158
|
+
| typeof SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT
|
|
159
|
+
| typeof SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_PROGRAM;
|
|
160
|
+
|
|
161
|
+
export const sendNexusErrorMessages: Record<SendNexusError, string> = {
|
|
162
|
+
[SEND_NEXUS_ERROR__AMBIGUOUS_FEE_SOURCE]: `Cannot specify both fee_preset and custom_fees`,
|
|
163
|
+
[SEND_NEXUS_ERROR__ARITHMETIC_OVERFLOW]: `Arithmetic overflow`,
|
|
164
|
+
[SEND_NEXUS_ERROR__DUPLICATE_AUTH_PLATFORM_NAME]: `Duplicate auth platform name`,
|
|
165
|
+
[SEND_NEXUS_ERROR__INSUFFICIENT_LIQUIDITY]: `Insufficient liquidity`,
|
|
166
|
+
[SEND_NEXUS_ERROR__INSUFFICIENT_STAKE]: `Insufficient stake balance`,
|
|
167
|
+
[SEND_NEXUS_ERROR__INVALID_AMOUNT]: `Invalid amount`,
|
|
168
|
+
[SEND_NEXUS_ERROR__INVALID_AUTHORITY]: `Invalid authority`,
|
|
169
|
+
[SEND_NEXUS_ERROR__INVALID_AUTH_PLATFORM_INDEX]: `Invalid auth platform index`,
|
|
170
|
+
[SEND_NEXUS_ERROR__INVALID_AUTH_PLATFORM_NAME]: `Invalid auth platform name`,
|
|
171
|
+
[SEND_NEXUS_ERROR__INVALID_CREATOR_ID]: `Creator identity is not a decodable wallet address`,
|
|
172
|
+
[SEND_NEXUS_ERROR__INVALID_DESTINATION]: `Invalid destination account`,
|
|
173
|
+
[SEND_NEXUS_ERROR__INVALID_FEE_PRESET]: `Invalid fee configuration`,
|
|
174
|
+
[SEND_NEXUS_ERROR__INVALID_MINT]: `Invalid mint`,
|
|
175
|
+
[SEND_NEXUS_ERROR__INVALID_PARTNER_CONFIG]: `Partner config address does not match its stored seeds`,
|
|
176
|
+
[SEND_NEXUS_ERROR__INVALID_PARTNER_NAME]: `Partner name cannot be empty`,
|
|
177
|
+
[SEND_NEXUS_ERROR__INVALID_PARTNER_NOTE]: `Invalid partner note`,
|
|
178
|
+
[SEND_NEXUS_ERROR__INVALID_PLATFORM_CONFIG]: `Platform config cannot be the default address`,
|
|
179
|
+
[SEND_NEXUS_ERROR__INVALID_PRESET_INDEX]: `Invalid preset index`,
|
|
180
|
+
[SEND_NEXUS_ERROR__INVALID_PRESET_NAME]: `Invalid preset name`,
|
|
181
|
+
[SEND_NEXUS_ERROR__INVALID_PYTH_ACCOUNT]: `Invalid Pyth price account`,
|
|
182
|
+
[SEND_NEXUS_ERROR__INVALID_PYTH_FEED]: `Invalid Pyth feed ID`,
|
|
183
|
+
[SEND_NEXUS_ERROR__INVALID_REWARD_ACCRUAL]: `Invalid reward accrual`,
|
|
184
|
+
[SEND_NEXUS_ERROR__INVALID_REWARD_MINT]: `Invalid reward mint`,
|
|
185
|
+
[SEND_NEXUS_ERROR__INVALID_REWARD_STATE]: `Invalid reward state`,
|
|
186
|
+
[SEND_NEXUS_ERROR__INVALID_SLUG]: `Invalid slug: must be non-empty, <= max_len bytes, lowercase alphanumeric or underscore`,
|
|
187
|
+
[SEND_NEXUS_ERROR__INVALID_STAKING_MINT]: `Invalid staking mint`,
|
|
188
|
+
[SEND_NEXUS_ERROR__INVALID_USDC_PRICE]: `USDC price must be non-zero - 0 means no price`,
|
|
189
|
+
[SEND_NEXUS_ERROR__INVALID_VAULT]: `Invalid vault`,
|
|
190
|
+
[SEND_NEXUS_ERROR__MISSING_FEE_SOURCE]: `Must provide either fee_preset or custom fees`,
|
|
191
|
+
[SEND_NEXUS_ERROR__NOTHING_TO_CLAIM]: `Nothing to claim`,
|
|
192
|
+
[SEND_NEXUS_ERROR__PARTNER_NOT_ON_PRESET]: `Partner account does not use this preset`,
|
|
193
|
+
[SEND_NEXUS_ERROR__PRESET_PLATFORM_MISMATCH]: `Fee preset belongs to a different platform`,
|
|
194
|
+
[SEND_NEXUS_ERROR__PROGRAM_PAUSED]: `Program is paused`,
|
|
195
|
+
[SEND_NEXUS_ERROR__QUOTE_MINT_PRICE_UNSET]: `Quote mint has no USDC price on its nexus reward state`,
|
|
196
|
+
[SEND_NEXUS_ERROR__RESERVED_PARTNER]: `Cannot add the default partner`,
|
|
197
|
+
[SEND_NEXUS_ERROR__REWARDS_NOT_SETTLED]: `Settle every reward mint before staking or unstaking - call settle for each registered mint`,
|
|
198
|
+
[SEND_NEXUS_ERROR__STAKING_ALREADY_ENABLED]: `Staking already enabled`,
|
|
199
|
+
[SEND_NEXUS_ERROR__STAKING_MINT_ALREADY_BOUND]: `Staking mint already bound`,
|
|
200
|
+
[SEND_NEXUS_ERROR__STAKING_NOT_ENABLED]: `Staking not enabled`,
|
|
201
|
+
[SEND_NEXUS_ERROR__TEXT_TOO_LONG]: `Text too long`,
|
|
202
|
+
[SEND_NEXUS_ERROR__TOO_MANY_AUTH_PLATFORMS]: `Too many auth platforms (max 255)`,
|
|
203
|
+
[SEND_NEXUS_ERROR__TRANSFER_FEE_NOT_SETTLEABLE]: `Token-2022 transfer fee schedule cannot settle the exact amount`,
|
|
204
|
+
[SEND_NEXUS_ERROR__UNAUTHORIZED]: `Unauthorized`,
|
|
205
|
+
[SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_INVALID]: `User token account is not an initialized token account`,
|
|
206
|
+
[SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY]: `User token account is not owned by the trading user`,
|
|
207
|
+
[SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT]: `User token account mint does not match the trade`,
|
|
208
|
+
[SEND_NEXUS_ERROR__USER_TOKEN_ACCOUNT_WRONG_PROGRAM]: `User token account owned by the wrong token program`,
|
|
209
|
+
} as const;
|
|
210
|
+
|
|
211
|
+
export function getSendNexusErrorMessage(code: SendNexusError): string {
|
|
212
|
+
return sendNexusErrorMessages[code];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function isSendNexusError<TProgramErrorCode extends SendNexusError>(
|
|
216
|
+
error: unknown,
|
|
217
|
+
transactionMessage: {
|
|
218
|
+
instructions: Record<number, { programAddress: Address }>;
|
|
219
|
+
},
|
|
220
|
+
code?: TProgramErrorCode,
|
|
221
|
+
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
|
|
222
|
+
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
|
|
223
|
+
return isProgramError<TProgramErrorCode>(
|
|
224
|
+
error,
|
|
225
|
+
transactionMessage,
|
|
226
|
+
SEND_NEXUS_PROGRAM_ADDRESS,
|
|
227
|
+
code,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
fixEncoderSize,
|
|
11
|
+
getBytesEncoder,
|
|
12
|
+
type ReadonlyUint8Array,
|
|
13
|
+
} from '@solana/kit';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Shared event-framing tag prepended to every CPI-framed event.
|
|
17
|
+
*
|
|
18
|
+
* `containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0)` checks whether data is a framed event
|
|
19
|
+
* at all — including event kinds unknown to this program.
|
|
20
|
+
*/
|
|
21
|
+
export const ANCHOR_EVENT_CPI_DISCRIMINATOR: ReadonlyUint8Array =
|
|
22
|
+
new Uint8Array([228, 69, 165, 46, 81, 203, 154, 29]);
|
|
23
|
+
|
|
24
|
+
export function getAnchorEventCpiDiscriminatorBytes(): ReadonlyUint8Array {
|
|
25
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
26
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
fixEncoderSize,
|
|
12
|
+
getAddressDecoder,
|
|
13
|
+
getBytesEncoder,
|
|
14
|
+
getI64Decoder,
|
|
15
|
+
getStructDecoder,
|
|
16
|
+
getU64Decoder,
|
|
17
|
+
type Address,
|
|
18
|
+
type FixedSizeDecoder,
|
|
19
|
+
type ReadonlyUint8Array,
|
|
20
|
+
} from '@solana/kit';
|
|
21
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
22
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
23
|
+
|
|
24
|
+
export const CLAIM_EVENT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
25
|
+
93, 15, 70, 170, 48, 140, 212, 219,
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
export function getClaimEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
29
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
30
|
+
CLAIM_EVENT_DISCRIMINATOR,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ClaimEvent = {
|
|
35
|
+
user: Address;
|
|
36
|
+
stakingConfig: Address;
|
|
37
|
+
rewardMint: Address;
|
|
38
|
+
amount: bigint;
|
|
39
|
+
timestamp: bigint;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let getClaimEventDecoderCache: FixedSizeDecoder<ClaimEvent> | undefined;
|
|
43
|
+
|
|
44
|
+
export function getClaimEventDecoder(): FixedSizeDecoder<ClaimEvent> {
|
|
45
|
+
return (getClaimEventDecoderCache ??= getStructDecoder([
|
|
46
|
+
['user', getAddressDecoder()],
|
|
47
|
+
['stakingConfig', getAddressDecoder()],
|
|
48
|
+
['rewardMint', getAddressDecoder()],
|
|
49
|
+
['amount', getU64Decoder()],
|
|
50
|
+
['timestamp', getI64Decoder()],
|
|
51
|
+
]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
56
|
+
* {@link ClaimEvent}, without decoding. Never throws.
|
|
57
|
+
*
|
|
58
|
+
* Returns `false` unless `event.programAddress` is SEND_NEXUS_PROGRAM_ADDRESS.
|
|
59
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
60
|
+
*
|
|
61
|
+
* @see parseClaimEvent to decode the matching data
|
|
62
|
+
*/
|
|
63
|
+
export function isClaimEvent(
|
|
64
|
+
event:
|
|
65
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
66
|
+
| ReadonlyUint8Array,
|
|
67
|
+
): boolean {
|
|
68
|
+
if ('data' in event && event.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS)
|
|
69
|
+
return false;
|
|
70
|
+
const data = 'data' in event ? event.data : event;
|
|
71
|
+
return (
|
|
72
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
73
|
+
containsBytes(data, CLAIM_EVENT_DISCRIMINATOR, 8)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parses raw event data as a {@link ClaimEvent}. Returns `null` on framing or discriminator
|
|
79
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
80
|
+
*
|
|
81
|
+
* Returns `null` unless `event.programAddress` is SEND_NEXUS_PROGRAM_ADDRESS.
|
|
82
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
83
|
+
*
|
|
84
|
+
* @see isClaimEvent to check without decoding
|
|
85
|
+
* @see identifySendNexusEvent to identify any program event
|
|
86
|
+
* @see parseSendNexusEvent
|
|
87
|
+
*/
|
|
88
|
+
export function parseClaimEvent(
|
|
89
|
+
event:
|
|
90
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
91
|
+
| ReadonlyUint8Array,
|
|
92
|
+
): ClaimEvent | null {
|
|
93
|
+
const checkedEvent =
|
|
94
|
+
'data' in event
|
|
95
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
96
|
+
: event;
|
|
97
|
+
if (!isClaimEvent(checkedEvent)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
101
|
+
return getClaimEventDecoder().decode(
|
|
102
|
+
data,
|
|
103
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
104
|
+
CLAIM_EVENT_DISCRIMINATOR.length,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 './anchorEventCpiDiscriminator.framing.js';
|
|
10
|
+
export * from './claimEvent.js';
|
|
11
|
+
export * from './sendNexus.events.js';
|
|
12
|
+
export * from './stakeEvent.js';
|
|
13
|
+
export * from './unstakeEvent.js';
|