@send-fun/sdk 1.1.0 → 2.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.
Files changed (80) hide show
  1. package/README.md +8 -9
  2. package/dist/index.cjs +777 -433
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +678 -217
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +678 -217
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +777 -433
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +7 -7
  11. package/src/dex/generated/accounts/globalConfig.ts +39 -2
  12. package/src/dex/generated/accounts/pool.ts +60 -9
  13. package/src/dex/generated/accounts/rewardAccrual.ts +39 -2
  14. package/src/dex/generated/errors/sendDex.ts +16 -8
  15. package/src/dex/generated/events/creatorClaimEvent.ts +3 -2
  16. package/src/dex/generated/events/poolCreateEvent.ts +8 -2
  17. package/src/dex/generated/events/tokenCreateEvent.ts +8 -9
  18. package/src/dex/generated/events/tradeEvent.ts +9 -2
  19. package/src/dex/generated/index.ts +1 -0
  20. package/src/dex/generated/instructions/claimCreatorFees.ts +21 -5
  21. package/src/{nexus → dex}/generated/pdas/creatorFeeConfig.ts +6 -6
  22. package/src/dex/generated/pdas/index.ts +1 -0
  23. package/src/dex/generated/plugins/sendDex.ts +3 -0
  24. package/src/dex/generated/shared/index.ts +52 -0
  25. package/src/dex/trade.ts +12 -13
  26. package/src/launchpad/create.ts +13 -38
  27. package/src/launchpad/generated/accounts/bondingCurve.ts +62 -9
  28. package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
  29. package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
  30. package/src/launchpad/generated/errors/sendLaunchpad.ts +12 -4
  31. package/src/launchpad/generated/events/completeEvent.ts +3 -2
  32. package/src/launchpad/generated/events/creatorClaimEvent.ts +3 -2
  33. package/src/launchpad/generated/events/migrateEvent.ts +3 -2
  34. package/src/launchpad/generated/events/tokenCreateEvent.ts +10 -9
  35. package/src/launchpad/generated/events/tradeEvent.ts +9 -2
  36. package/src/launchpad/generated/index.ts +1 -0
  37. package/src/launchpad/generated/instructions/claimCreatorFees.ts +17 -4
  38. package/src/launchpad/generated/instructions/createToken.ts +32 -50
  39. package/src/launchpad/generated/instructions/migrate.ts +79 -12
  40. package/src/launchpad/generated/pdas/creatorFeeConfig.ts +39 -0
  41. package/src/launchpad/generated/pdas/index.ts +1 -0
  42. package/src/launchpad/generated/plugins/sendLaunchpad.ts +3 -0
  43. package/src/launchpad/generated/shared/index.ts +52 -0
  44. package/src/launchpad/migrate.ts +7 -4
  45. package/src/launchpad/trade.ts +15 -15
  46. package/src/math/amm.ts +40 -33
  47. package/src/math/fee-decay.ts +3 -2
  48. package/src/math/fees.ts +4 -2
  49. package/src/math/internal.ts +1 -1
  50. package/src/nexus/fee-helpers.ts +10 -5
  51. package/src/nexus/generated/accounts/altRegistry.ts +41 -2
  52. package/src/nexus/generated/accounts/feePreset.ts +43 -4
  53. package/src/nexus/generated/accounts/globalConfig.ts +39 -2
  54. package/src/nexus/generated/accounts/index.ts +0 -1
  55. package/src/nexus/generated/accounts/partnerConfig.ts +48 -5
  56. package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
  57. package/src/nexus/generated/accounts/rewardState.ts +41 -2
  58. package/src/nexus/generated/accounts/sendNexus.accounts.ts +0 -5
  59. package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
  60. package/src/nexus/generated/accounts/userRewardDebt.ts +42 -5
  61. package/src/nexus/generated/accounts/userStakePosition.ts +42 -5
  62. package/src/nexus/generated/errors/sendNexus.ts +12 -4
  63. package/src/nexus/generated/index.ts +1 -0
  64. package/src/nexus/generated/pdas/index.ts +0 -1
  65. package/src/nexus/generated/plugins/sendNexus.ts +0 -35
  66. package/src/nexus/generated/shared/index.ts +52 -0
  67. package/src/nexus/generated/types/dexFees.ts +4 -4
  68. package/src/nexus/generated/types/index.ts +0 -1
  69. package/src/nexus/generated/types/launchpadFees.ts +4 -4
  70. package/src/nexus/staking.ts +45 -41
  71. package/src/platform.ts +2 -2
  72. package/src/transfer-fee.ts +19 -17
  73. package/src/utils/chunk.ts +1 -1
  74. package/src/utils/index.ts +2 -5
  75. package/src/utils/mint-info.ts +8 -7
  76. package/src/utils/partner.ts +1 -1
  77. package/src/utils/pda.ts +1 -1
  78. package/src/nexus/generated/accounts/creatorFeeConfig.ts +0 -200
  79. package/src/nexus/generated/types/callerType.ts +0 -38
  80. package/src/utils/creator-hash.ts +0 -57
@@ -22,6 +22,8 @@ import {
22
22
  getBytesEncoder,
23
23
  getStructDecoder,
24
24
  getStructEncoder,
25
+ getU16Decoder,
26
+ getU16Encoder,
25
27
  getU8Decoder,
26
28
  getU8Encoder,
27
29
  transformEncoder,
@@ -38,6 +40,7 @@ import {
38
40
  type ReadonlyUint8Array,
39
41
  } from '@solana/kit';
40
42
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
43
+ import { accountIsCreated } from '../shared/index.js';
41
44
  import {
42
45
  getDexFeesDecoder,
43
46
  getDexFeesEncoder,
@@ -69,6 +72,7 @@ export type PartnerConfig = {
69
72
  launchpad: LaunchpadFees;
70
73
  dex: DexFees;
71
74
  platformConfig: Address;
75
+ allowedCreatorFeeModes: number;
72
76
  reserved: ReadonlyUint8Array;
73
77
  };
74
78
 
@@ -81,6 +85,7 @@ export type PartnerConfigArgs = {
81
85
  launchpad: LaunchpadFeesArgs;
82
86
  dex: DexFeesArgs;
83
87
  platformConfig: Address;
88
+ allowedCreatorFeeModes: number;
84
89
  reserved: ReadonlyUint8Array;
85
90
  };
86
91
 
@@ -97,7 +102,8 @@ export function getPartnerConfigEncoder(): FixedSizeEncoder<PartnerConfigArgs> {
97
102
  ['launchpad', getLaunchpadFeesEncoder()],
98
103
  ['dex', getDexFeesEncoder()],
99
104
  ['platformConfig', getAddressEncoder()],
100
- ['reserved', fixEncoderSize(getBytesEncoder(), 32)],
105
+ ['allowedCreatorFeeModes', getU16Encoder()],
106
+ ['reserved', fixEncoderSize(getBytesEncoder(), 256)],
101
107
  ]),
102
108
  (value) => ({ ...value, discriminator: PARTNER_CONFIG_DISCRIMINATOR }),
103
109
  );
@@ -115,7 +121,8 @@ export function getPartnerConfigDecoder(): FixedSizeDecoder<PartnerConfig> {
115
121
  ['launchpad', getLaunchpadFeesDecoder()],
116
122
  ['dex', getDexFeesDecoder()],
117
123
  ['platformConfig', getAddressDecoder()],
118
- ['reserved', fixDecoderSize(getBytesDecoder(), 32)],
124
+ ['allowedCreatorFeeModes', getU16Decoder()],
125
+ ['reserved', fixDecoderSize(getBytesDecoder(), 256)],
119
126
  ]);
120
127
  }
121
128
 
@@ -127,9 +134,25 @@ export function getPartnerConfigCodec(): FixedSizeCodec<
127
134
  return combineCodec(getPartnerConfigEncoder(), getPartnerConfigDecoder());
128
135
  }
129
136
 
137
+ /**
138
+ * Decodes a `PartnerConfig` account, throwing when another program owns it or its discriminator
139
+ * does not match.
140
+ *
141
+ * Unlike {@link fetchMaybePartnerConfig}, this throws for an address that only holds lamports rather
142
+ * than returning the non-existing variant: an account passed as existing must never come back as that
143
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
144
+ */
130
145
  export function decodePartnerConfig<TAddress extends string = string>(
131
146
  encodedAccount: EncodedAccount<TAddress>,
132
147
  ): Account<PartnerConfig, TAddress>;
148
+ /**
149
+ * Decodes a `PartnerConfig` account, throwing when another program owns it or its discriminator
150
+ * does not match.
151
+ *
152
+ * Unlike {@link fetchMaybePartnerConfig}, this throws for an address that only holds lamports rather
153
+ * than returning the non-existing variant: an account passed as existing must never come back as that
154
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
155
+ */
133
156
  export function decodePartnerConfig<TAddress extends string = string>(
134
157
  encodedAccount: MaybeEncodedAccount<TAddress>,
135
158
  ): MaybeAccount<PartnerConfig, TAddress>;
@@ -160,6 +183,7 @@ export function decodePartnerConfig<TAddress extends string = string>(
160
183
  );
161
184
  }
162
185
 
186
+ /** Fetches a `PartnerConfig` account, throwing when it does not exist or only holds lamports. */
163
187
  export async function fetchPartnerConfig<TAddress extends string = string>(
164
188
  rpc: Parameters<typeof fetchEncodedAccount>[0],
165
189
  address: Address<TAddress>,
@@ -170,15 +194,25 @@ export async function fetchPartnerConfig<TAddress extends string = string>(
170
194
  return maybeAccount;
171
195
  }
172
196
 
197
+ /**
198
+ * Fetches a `PartnerConfig` account, or the non-existing variant when the address holds no
199
+ * account or only lamports (see {@link accountIsCreated}).
200
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
201
+ */
173
202
  export async function fetchMaybePartnerConfig<TAddress extends string = string>(
174
203
  rpc: Parameters<typeof fetchEncodedAccount>[0],
175
204
  address: Address<TAddress>,
176
205
  config?: FetchAccountConfig,
177
206
  ): Promise<MaybeAccount<PartnerConfig, TAddress>> {
178
207
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
179
- return decodePartnerConfig(maybeAccount);
208
+ return decodePartnerConfig(
209
+ accountIsCreated(maybeAccount)
210
+ ? maybeAccount
211
+ : { address, exists: false },
212
+ );
180
213
  }
181
214
 
215
+ /** Fetches `PartnerConfig` accounts, throwing when any does not exist or only holds lamports. */
182
216
  export async function fetchAllPartnerConfig(
183
217
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
184
218
  addresses: Array<Address>,
@@ -193,6 +227,11 @@ export async function fetchAllPartnerConfig(
193
227
  return maybeAccounts;
194
228
  }
195
229
 
230
+ /**
231
+ * Fetches `PartnerConfig` accounts, with the non-existing variant for each address that holds
232
+ * no account or only lamports (see {@link accountIsCreated}).
233
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
234
+ */
196
235
  export async function fetchAllMaybePartnerConfig(
197
236
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
198
237
  addresses: Array<Address>,
@@ -200,10 +239,14 @@ export async function fetchAllMaybePartnerConfig(
200
239
  ): Promise<MaybeAccount<PartnerConfig>[]> {
201
240
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
202
241
  return maybeAccounts.map((maybeAccount) =>
203
- decodePartnerConfig(maybeAccount),
242
+ decodePartnerConfig(
243
+ accountIsCreated(maybeAccount)
244
+ ? maybeAccount
245
+ : { address: maybeAccount.address, exists: false },
246
+ ),
204
247
  );
205
248
  }
206
249
 
207
250
  export function getPartnerConfigSize(): number {
208
- return 173;
251
+ return 399;
209
252
  }
@@ -46,6 +46,7 @@ import {
46
46
  type ReadonlyUint8Array,
47
47
  } from '@solana/kit';
48
48
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
49
+ import { accountIsCreated } from '../shared/index.js';
49
50
 
50
51
  export const PARTNER_METADATA_DISCRIMINATOR: ReadonlyUint8Array =
51
52
  new Uint8Array([68, 68, 130, 19, 16, 209, 98, 156]);
@@ -130,9 +131,25 @@ export function getPartnerMetadataCodec(): Codec<
130
131
  );
131
132
  }
132
133
 
134
+ /**
135
+ * Decodes a `PartnerMetadata` account, throwing when another program owns it or its discriminator
136
+ * does not match.
137
+ *
138
+ * Unlike {@link fetchMaybePartnerMetadata}, this throws for an address that only holds lamports rather
139
+ * than returning the non-existing variant: an account passed as existing must never come back as that
140
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
141
+ */
133
142
  export function decodePartnerMetadata<TAddress extends string = string>(
134
143
  encodedAccount: EncodedAccount<TAddress>,
135
144
  ): Account<PartnerMetadata, TAddress>;
145
+ /**
146
+ * Decodes a `PartnerMetadata` account, throwing when another program owns it or its discriminator
147
+ * does not match.
148
+ *
149
+ * Unlike {@link fetchMaybePartnerMetadata}, this throws for an address that only holds lamports rather
150
+ * than returning the non-existing variant: an account passed as existing must never come back as that
151
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
152
+ */
136
153
  export function decodePartnerMetadata<TAddress extends string = string>(
137
154
  encodedAccount: MaybeEncodedAccount<TAddress>,
138
155
  ): MaybeAccount<PartnerMetadata, TAddress>;
@@ -169,6 +186,7 @@ export function decodePartnerMetadata<TAddress extends string = string>(
169
186
  );
170
187
  }
171
188
 
189
+ /** Fetches a `PartnerMetadata` account, throwing when it does not exist or only holds lamports. */
172
190
  export async function fetchPartnerMetadata<TAddress extends string = string>(
173
191
  rpc: Parameters<typeof fetchEncodedAccount>[0],
174
192
  address: Address<TAddress>,
@@ -179,6 +197,11 @@ export async function fetchPartnerMetadata<TAddress extends string = string>(
179
197
  return maybeAccount;
180
198
  }
181
199
 
200
+ /**
201
+ * Fetches a `PartnerMetadata` account, or the non-existing variant when the address holds no
202
+ * account or only lamports (see {@link accountIsCreated}).
203
+ * {@link decodePartnerMetadata} throws for a lamports-only account instead.
204
+ */
182
205
  export async function fetchMaybePartnerMetadata<
183
206
  TAddress extends string = string,
184
207
  >(
@@ -187,9 +210,14 @@ export async function fetchMaybePartnerMetadata<
187
210
  config?: FetchAccountConfig,
188
211
  ): Promise<MaybeAccount<PartnerMetadata, TAddress>> {
189
212
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
190
- return decodePartnerMetadata(maybeAccount);
213
+ return decodePartnerMetadata(
214
+ accountIsCreated(maybeAccount)
215
+ ? maybeAccount
216
+ : { address, exists: false },
217
+ );
191
218
  }
192
219
 
220
+ /** Fetches `PartnerMetadata` accounts, throwing when any does not exist or only holds lamports. */
193
221
  export async function fetchAllPartnerMetadata(
194
222
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
195
223
  addresses: Array<Address>,
@@ -204,6 +232,11 @@ export async function fetchAllPartnerMetadata(
204
232
  return maybeAccounts;
205
233
  }
206
234
 
235
+ /**
236
+ * Fetches `PartnerMetadata` accounts, with the non-existing variant for each address that holds
237
+ * no account or only lamports (see {@link accountIsCreated}).
238
+ * {@link decodePartnerMetadata} throws for a lamports-only account instead.
239
+ */
207
240
  export async function fetchAllMaybePartnerMetadata(
208
241
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
209
242
  addresses: Array<Address>,
@@ -211,6 +244,10 @@ export async function fetchAllMaybePartnerMetadata(
211
244
  ): Promise<MaybeAccount<PartnerMetadata>[]> {
212
245
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
213
246
  return maybeAccounts.map((maybeAccount) =>
214
- decodePartnerMetadata(maybeAccount),
247
+ decodePartnerMetadata(
248
+ accountIsCreated(maybeAccount)
249
+ ? maybeAccount
250
+ : { address: maybeAccount.address, exists: false },
251
+ ),
215
252
  );
216
253
  }
@@ -42,6 +42,7 @@ import {
42
42
  type ReadonlyUint8Array,
43
43
  } from '@solana/kit';
44
44
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
45
+ import { accountIsCreated } from '../shared/index.js';
45
46
 
46
47
  export const REWARD_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
47
48
  86, 245, 149, 170, 90, 108, 31, 251,
@@ -129,9 +130,25 @@ export function getRewardStateCodec(): FixedSizeCodec<
129
130
  return combineCodec(getRewardStateEncoder(), getRewardStateDecoder());
130
131
  }
131
132
 
133
+ /**
134
+ * Decodes a `RewardState` account, throwing when another program owns it or its discriminator
135
+ * does not match.
136
+ *
137
+ * Unlike {@link fetchMaybeRewardState}, this throws for an address that only holds lamports rather
138
+ * than returning the non-existing variant: an account passed as existing must never come back as that
139
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
140
+ */
132
141
  export function decodeRewardState<TAddress extends string = string>(
133
142
  encodedAccount: EncodedAccount<TAddress>,
134
143
  ): Account<RewardState, TAddress>;
144
+ /**
145
+ * Decodes a `RewardState` account, throwing when another program owns it or its discriminator
146
+ * does not match.
147
+ *
148
+ * Unlike {@link fetchMaybeRewardState}, this throws for an address that only holds lamports rather
149
+ * than returning the non-existing variant: an account passed as existing must never come back as that
150
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
151
+ */
135
152
  export function decodeRewardState<TAddress extends string = string>(
136
153
  encodedAccount: MaybeEncodedAccount<TAddress>,
137
154
  ): MaybeAccount<RewardState, TAddress>;
@@ -162,6 +179,7 @@ export function decodeRewardState<TAddress extends string = string>(
162
179
  );
163
180
  }
164
181
 
182
+ /** Fetches a `RewardState` account, throwing when it does not exist or only holds lamports. */
165
183
  export async function fetchRewardState<TAddress extends string = string>(
166
184
  rpc: Parameters<typeof fetchEncodedAccount>[0],
167
185
  address: Address<TAddress>,
@@ -172,15 +190,25 @@ export async function fetchRewardState<TAddress extends string = string>(
172
190
  return maybeAccount;
173
191
  }
174
192
 
193
+ /**
194
+ * Fetches a `RewardState` account, or the non-existing variant when the address holds no
195
+ * account or only lamports (see {@link accountIsCreated}).
196
+ * {@link decodeRewardState} throws for a lamports-only account instead.
197
+ */
175
198
  export async function fetchMaybeRewardState<TAddress extends string = string>(
176
199
  rpc: Parameters<typeof fetchEncodedAccount>[0],
177
200
  address: Address<TAddress>,
178
201
  config?: FetchAccountConfig,
179
202
  ): Promise<MaybeAccount<RewardState, TAddress>> {
180
203
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
181
- return decodeRewardState(maybeAccount);
204
+ return decodeRewardState(
205
+ accountIsCreated(maybeAccount)
206
+ ? maybeAccount
207
+ : { address, exists: false },
208
+ );
182
209
  }
183
210
 
211
+ /** Fetches `RewardState` accounts, throwing when any does not exist or only holds lamports. */
184
212
  export async function fetchAllRewardState(
185
213
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
186
214
  addresses: Array<Address>,
@@ -195,13 +223,24 @@ export async function fetchAllRewardState(
195
223
  return maybeAccounts;
196
224
  }
197
225
 
226
+ /**
227
+ * Fetches `RewardState` accounts, with the non-existing variant for each address that holds
228
+ * no account or only lamports (see {@link accountIsCreated}).
229
+ * {@link decodeRewardState} throws for a lamports-only account instead.
230
+ */
198
231
  export async function fetchAllMaybeRewardState(
199
232
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
200
233
  addresses: Array<Address>,
201
234
  config?: FetchAccountsConfig,
202
235
  ): Promise<MaybeAccount<RewardState>[]> {
203
236
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
204
- return maybeAccounts.map((maybeAccount) => decodeRewardState(maybeAccount));
237
+ return maybeAccounts.map((maybeAccount) =>
238
+ decodeRewardState(
239
+ accountIsCreated(maybeAccount)
240
+ ? maybeAccount
241
+ : { address: maybeAccount.address, exists: false },
242
+ ),
243
+ );
205
244
  }
206
245
 
207
246
  export function getRewardStateSize(): number {
@@ -13,7 +13,6 @@ import {
13
13
  } from '@solana/kit';
14
14
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
15
15
  import { ALT_REGISTRY_DISCRIMINATOR } from './altRegistry.js';
16
- import { CREATOR_FEE_CONFIG_DISCRIMINATOR } from './creatorFeeConfig.js';
17
16
  import { FEE_PRESET_DISCRIMINATOR } from './feePreset.js';
18
17
  import { GLOBAL_CONFIG_DISCRIMINATOR } from './globalConfig.js';
19
18
  import { PARTNER_CONFIG_DISCRIMINATOR } from './partnerConfig.js';
@@ -26,7 +25,6 @@ import { USER_STAKE_POSITION_DISCRIMINATOR } from './userStakePosition.js';
26
25
  /** Account kinds of the sendNexus program. */
27
26
  export type SendNexusAccountType =
28
27
  | 'altRegistry'
29
- | 'creatorFeeConfig'
30
28
  | 'feePreset'
31
29
  | 'globalConfig'
32
30
  | 'partnerConfig'
@@ -54,9 +52,6 @@ export function identifySendNexusAccount(
54
52
  if (containsBytes(data, ALT_REGISTRY_DISCRIMINATOR, 0)) {
55
53
  return 'altRegistry';
56
54
  }
57
- if (containsBytes(data, CREATOR_FEE_CONFIG_DISCRIMINATOR, 0)) {
58
- return 'creatorFeeConfig';
59
- }
60
55
  if (containsBytes(data, FEE_PRESET_DISCRIMINATOR, 0)) {
61
56
  return 'feePreset';
62
57
  }
@@ -44,6 +44,7 @@ import {
44
44
  type ReadonlyUint8Array,
45
45
  } from '@solana/kit';
46
46
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
47
+ import { accountIsCreated } from '../shared/index.js';
47
48
 
48
49
  export const STAKING_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
49
50
  45, 134, 252, 82, 37, 57, 84, 25,
@@ -115,9 +116,25 @@ export function getStakingConfigCodec(): FixedSizeCodec<
115
116
  return combineCodec(getStakingConfigEncoder(), getStakingConfigDecoder());
116
117
  }
117
118
 
119
+ /**
120
+ * Decodes a `StakingConfig` account, throwing when another program owns it or its discriminator
121
+ * does not match.
122
+ *
123
+ * Unlike {@link fetchMaybeStakingConfig}, this throws for an address that only holds lamports rather
124
+ * than returning the non-existing variant: an account passed as existing must never come back as that
125
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
126
+ */
118
127
  export function decodeStakingConfig<TAddress extends string = string>(
119
128
  encodedAccount: EncodedAccount<TAddress>,
120
129
  ): Account<StakingConfig, TAddress>;
130
+ /**
131
+ * Decodes a `StakingConfig` account, throwing when another program owns it or its discriminator
132
+ * does not match.
133
+ *
134
+ * Unlike {@link fetchMaybeStakingConfig}, this throws for an address that only holds lamports rather
135
+ * than returning the non-existing variant: an account passed as existing must never come back as that
136
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
137
+ */
121
138
  export function decodeStakingConfig<TAddress extends string = string>(
122
139
  encodedAccount: MaybeEncodedAccount<TAddress>,
123
140
  ): MaybeAccount<StakingConfig, TAddress>;
@@ -148,6 +165,7 @@ export function decodeStakingConfig<TAddress extends string = string>(
148
165
  );
149
166
  }
150
167
 
168
+ /** Fetches a `StakingConfig` account, throwing when it does not exist or only holds lamports. */
151
169
  export async function fetchStakingConfig<TAddress extends string = string>(
152
170
  rpc: Parameters<typeof fetchEncodedAccount>[0],
153
171
  address: Address<TAddress>,
@@ -158,15 +176,25 @@ export async function fetchStakingConfig<TAddress extends string = string>(
158
176
  return maybeAccount;
159
177
  }
160
178
 
179
+ /**
180
+ * Fetches a `StakingConfig` account, or the non-existing variant when the address holds no
181
+ * account or only lamports (see {@link accountIsCreated}).
182
+ * {@link decodeStakingConfig} throws for a lamports-only account instead.
183
+ */
161
184
  export async function fetchMaybeStakingConfig<TAddress extends string = string>(
162
185
  rpc: Parameters<typeof fetchEncodedAccount>[0],
163
186
  address: Address<TAddress>,
164
187
  config?: FetchAccountConfig,
165
188
  ): Promise<MaybeAccount<StakingConfig, TAddress>> {
166
189
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
167
- return decodeStakingConfig(maybeAccount);
190
+ return decodeStakingConfig(
191
+ accountIsCreated(maybeAccount)
192
+ ? maybeAccount
193
+ : { address, exists: false },
194
+ );
168
195
  }
169
196
 
197
+ /** Fetches `StakingConfig` accounts, throwing when any does not exist or only holds lamports. */
170
198
  export async function fetchAllStakingConfig(
171
199
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
172
200
  addresses: Array<Address>,
@@ -181,6 +209,11 @@ export async function fetchAllStakingConfig(
181
209
  return maybeAccounts;
182
210
  }
183
211
 
212
+ /**
213
+ * Fetches `StakingConfig` accounts, with the non-existing variant for each address that holds
214
+ * no account or only lamports (see {@link accountIsCreated}).
215
+ * {@link decodeStakingConfig} throws for a lamports-only account instead.
216
+ */
184
217
  export async function fetchAllMaybeStakingConfig(
185
218
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
186
219
  addresses: Array<Address>,
@@ -188,7 +221,11 @@ export async function fetchAllMaybeStakingConfig(
188
221
  ): Promise<MaybeAccount<StakingConfig>[]> {
189
222
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
190
223
  return maybeAccounts.map((maybeAccount) =>
191
- decodeStakingConfig(maybeAccount),
224
+ decodeStakingConfig(
225
+ accountIsCreated(maybeAccount)
226
+ ? maybeAccount
227
+ : { address: maybeAccount.address, exists: false },
228
+ ),
192
229
  );
193
230
  }
194
231
 
@@ -44,6 +44,7 @@ import {
44
44
  type ReadonlyUint8Array,
45
45
  } from '@solana/kit';
46
46
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
47
+ import { accountIsCreated } from '../shared/index.js';
47
48
 
48
49
  export const USER_REWARD_DEBT_DISCRIMINATOR: ReadonlyUint8Array =
49
50
  new Uint8Array([92, 166, 184, 23, 127, 201, 251, 148]);
@@ -98,7 +99,7 @@ export function getUserRewardDebtEncoder(): FixedSizeEncoder<UserRewardDebtArgs>
98
99
  ['amountSnapshot', getU64Encoder()],
99
100
  ['settledVersion', getU32Encoder()],
100
101
  ['owed', getU64Encoder()],
101
- ['reserved', fixEncoderSize(getBytesEncoder(), 32)],
102
+ ['reserved', fixEncoderSize(getBytesEncoder(), 64)],
102
103
  ]),
103
104
  (value) => ({
104
105
  ...value,
@@ -121,7 +122,7 @@ export function getUserRewardDebtDecoder(): FixedSizeDecoder<UserRewardDebt> {
121
122
  ['amountSnapshot', getU64Decoder()],
122
123
  ['settledVersion', getU32Decoder()],
123
124
  ['owed', getU64Decoder()],
124
- ['reserved', fixDecoderSize(getBytesDecoder(), 32)],
125
+ ['reserved', fixDecoderSize(getBytesDecoder(), 64)],
125
126
  ]);
126
127
  }
127
128
 
@@ -133,9 +134,25 @@ export function getUserRewardDebtCodec(): FixedSizeCodec<
133
134
  return combineCodec(getUserRewardDebtEncoder(), getUserRewardDebtDecoder());
134
135
  }
135
136
 
137
+ /**
138
+ * Decodes a `UserRewardDebt` account, throwing when another program owns it or its discriminator
139
+ * does not match.
140
+ *
141
+ * Unlike {@link fetchMaybeUserRewardDebt}, this throws for an address that only holds lamports rather
142
+ * than returning the non-existing variant: an account passed as existing must never come back as that
143
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
144
+ */
136
145
  export function decodeUserRewardDebt<TAddress extends string = string>(
137
146
  encodedAccount: EncodedAccount<TAddress>,
138
147
  ): Account<UserRewardDebt, TAddress>;
148
+ /**
149
+ * Decodes a `UserRewardDebt` account, throwing when another program owns it or its discriminator
150
+ * does not match.
151
+ *
152
+ * Unlike {@link fetchMaybeUserRewardDebt}, this throws for an address that only holds lamports rather
153
+ * than returning the non-existing variant: an account passed as existing must never come back as that
154
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
155
+ */
139
156
  export function decodeUserRewardDebt<TAddress extends string = string>(
140
157
  encodedAccount: MaybeEncodedAccount<TAddress>,
141
158
  ): MaybeAccount<UserRewardDebt, TAddress>;
@@ -170,6 +187,7 @@ export function decodeUserRewardDebt<TAddress extends string = string>(
170
187
  );
171
188
  }
172
189
 
190
+ /** Fetches a `UserRewardDebt` account, throwing when it does not exist or only holds lamports. */
173
191
  export async function fetchUserRewardDebt<TAddress extends string = string>(
174
192
  rpc: Parameters<typeof fetchEncodedAccount>[0],
175
193
  address: Address<TAddress>,
@@ -180,6 +198,11 @@ export async function fetchUserRewardDebt<TAddress extends string = string>(
180
198
  return maybeAccount;
181
199
  }
182
200
 
201
+ /**
202
+ * Fetches a `UserRewardDebt` account, or the non-existing variant when the address holds no
203
+ * account or only lamports (see {@link accountIsCreated}).
204
+ * {@link decodeUserRewardDebt} throws for a lamports-only account instead.
205
+ */
183
206
  export async function fetchMaybeUserRewardDebt<
184
207
  TAddress extends string = string,
185
208
  >(
@@ -188,9 +211,14 @@ export async function fetchMaybeUserRewardDebt<
188
211
  config?: FetchAccountConfig,
189
212
  ): Promise<MaybeAccount<UserRewardDebt, TAddress>> {
190
213
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
191
- return decodeUserRewardDebt(maybeAccount);
214
+ return decodeUserRewardDebt(
215
+ accountIsCreated(maybeAccount)
216
+ ? maybeAccount
217
+ : { address, exists: false },
218
+ );
192
219
  }
193
220
 
221
+ /** Fetches `UserRewardDebt` accounts, throwing when any does not exist or only holds lamports. */
194
222
  export async function fetchAllUserRewardDebt(
195
223
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
196
224
  addresses: Array<Address>,
@@ -205,6 +233,11 @@ export async function fetchAllUserRewardDebt(
205
233
  return maybeAccounts;
206
234
  }
207
235
 
236
+ /**
237
+ * Fetches `UserRewardDebt` accounts, with the non-existing variant for each address that holds
238
+ * no account or only lamports (see {@link accountIsCreated}).
239
+ * {@link decodeUserRewardDebt} throws for a lamports-only account instead.
240
+ */
208
241
  export async function fetchAllMaybeUserRewardDebt(
209
242
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
210
243
  addresses: Array<Address>,
@@ -212,10 +245,14 @@ export async function fetchAllMaybeUserRewardDebt(
212
245
  ): Promise<MaybeAccount<UserRewardDebt>[]> {
213
246
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
214
247
  return maybeAccounts.map((maybeAccount) =>
215
- decodeUserRewardDebt(maybeAccount),
248
+ decodeUserRewardDebt(
249
+ accountIsCreated(maybeAccount)
250
+ ? maybeAccount
251
+ : { address: maybeAccount.address, exists: false },
252
+ ),
216
253
  );
217
254
  }
218
255
 
219
256
  export function getUserRewardDebtSize(): number {
220
- return 182;
257
+ return 214;
221
258
  }
@@ -44,6 +44,7 @@ import {
44
44
  type ReadonlyUint8Array,
45
45
  } from '@solana/kit';
46
46
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
47
+ import { accountIsCreated } from '../shared/index.js';
47
48
 
48
49
  export const USER_STAKE_POSITION_DISCRIMINATOR: ReadonlyUint8Array =
49
50
  new Uint8Array([123, 46, 248, 17, 240, 135, 201, 17]);
@@ -89,7 +90,7 @@ export function getUserStakePositionEncoder(): FixedSizeEncoder<UserStakePositio
89
90
  ['amount', getU64Encoder()],
90
91
  ['stakeVersion', getU32Encoder()],
91
92
  ['settledCount', getU16Encoder()],
92
- ['reserved', fixEncoderSize(getBytesEncoder(), 32)],
93
+ ['reserved', fixEncoderSize(getBytesEncoder(), 128)],
93
94
  ]),
94
95
  (value) => ({
95
96
  ...value,
@@ -109,7 +110,7 @@ export function getUserStakePositionDecoder(): FixedSizeDecoder<UserStakePositio
109
110
  ['amount', getU64Decoder()],
110
111
  ['stakeVersion', getU32Decoder()],
111
112
  ['settledCount', getU16Decoder()],
112
- ['reserved', fixDecoderSize(getBytesDecoder(), 32)],
113
+ ['reserved', fixDecoderSize(getBytesDecoder(), 128)],
113
114
  ]);
114
115
  }
115
116
 
@@ -124,9 +125,25 @@ export function getUserStakePositionCodec(): FixedSizeCodec<
124
125
  );
125
126
  }
126
127
 
128
+ /**
129
+ * Decodes a `UserStakePosition` account, throwing when another program owns it or its discriminator
130
+ * does not match.
131
+ *
132
+ * Unlike {@link fetchMaybeUserStakePosition}, this throws for an address that only holds lamports rather
133
+ * than returning the non-existing variant: an account passed as existing must never come back as that
134
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
135
+ */
127
136
  export function decodeUserStakePosition<TAddress extends string = string>(
128
137
  encodedAccount: EncodedAccount<TAddress>,
129
138
  ): Account<UserStakePosition, TAddress>;
139
+ /**
140
+ * Decodes a `UserStakePosition` account, throwing when another program owns it or its discriminator
141
+ * does not match.
142
+ *
143
+ * Unlike {@link fetchMaybeUserStakePosition}, this throws for an address that only holds lamports rather
144
+ * than returning the non-existing variant: an account passed as existing must never come back as that
145
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
146
+ */
130
147
  export function decodeUserStakePosition<TAddress extends string = string>(
131
148
  encodedAccount: MaybeEncodedAccount<TAddress>,
132
149
  ): MaybeAccount<UserStakePosition, TAddress>;
@@ -163,6 +180,7 @@ export function decodeUserStakePosition<TAddress extends string = string>(
163
180
  );
164
181
  }
165
182
 
183
+ /** Fetches a `UserStakePosition` account, throwing when it does not exist or only holds lamports. */
166
184
  export async function fetchUserStakePosition<TAddress extends string = string>(
167
185
  rpc: Parameters<typeof fetchEncodedAccount>[0],
168
186
  address: Address<TAddress>,
@@ -177,6 +195,11 @@ export async function fetchUserStakePosition<TAddress extends string = string>(
177
195
  return maybeAccount;
178
196
  }
179
197
 
198
+ /**
199
+ * Fetches a `UserStakePosition` account, or the non-existing variant when the address holds no
200
+ * account or only lamports (see {@link accountIsCreated}).
201
+ * {@link decodeUserStakePosition} throws for a lamports-only account instead.
202
+ */
180
203
  export async function fetchMaybeUserStakePosition<
181
204
  TAddress extends string = string,
182
205
  >(
@@ -185,9 +208,14 @@ export async function fetchMaybeUserStakePosition<
185
208
  config?: FetchAccountConfig,
186
209
  ): Promise<MaybeAccount<UserStakePosition, TAddress>> {
187
210
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
188
- return decodeUserStakePosition(maybeAccount);
211
+ return decodeUserStakePosition(
212
+ accountIsCreated(maybeAccount)
213
+ ? maybeAccount
214
+ : { address, exists: false },
215
+ );
189
216
  }
190
217
 
218
+ /** Fetches `UserStakePosition` accounts, throwing when any does not exist or only holds lamports. */
191
219
  export async function fetchAllUserStakePosition(
192
220
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
193
221
  addresses: Array<Address>,
@@ -202,6 +230,11 @@ export async function fetchAllUserStakePosition(
202
230
  return maybeAccounts;
203
231
  }
204
232
 
233
+ /**
234
+ * Fetches `UserStakePosition` accounts, with the non-existing variant for each address that holds
235
+ * no account or only lamports (see {@link accountIsCreated}).
236
+ * {@link decodeUserStakePosition} throws for a lamports-only account instead.
237
+ */
205
238
  export async function fetchAllMaybeUserStakePosition(
206
239
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
207
240
  addresses: Array<Address>,
@@ -209,10 +242,14 @@ export async function fetchAllMaybeUserStakePosition(
209
242
  ): Promise<MaybeAccount<UserStakePosition>[]> {
210
243
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
211
244
  return maybeAccounts.map((maybeAccount) =>
212
- decodeUserStakePosition(maybeAccount),
245
+ decodeUserStakePosition(
246
+ accountIsCreated(maybeAccount)
247
+ ? maybeAccount
248
+ : { address: maybeAccount.address, exists: false },
249
+ ),
213
250
  );
214
251
  }
215
252
 
216
253
  export function getUserStakePositionSize(): number {
217
- return 120;
254
+ return 216;
218
255
  }