@send-fun/sdk 1.1.0 → 1.2.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 (50) hide show
  1. package/README.md +8 -9
  2. package/dist/index.cjs +526 -98
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +595 -93
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +595 -93
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +526 -98
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +1 -1
  11. package/src/dex/generated/accounts/globalConfig.ts +39 -2
  12. package/src/dex/generated/accounts/pool.ts +41 -2
  13. package/src/dex/generated/accounts/rewardAccrual.ts +39 -2
  14. package/src/dex/generated/index.ts +1 -0
  15. package/src/dex/generated/shared/index.ts +52 -0
  16. package/src/dex/trade.ts +12 -13
  17. package/src/launchpad/create.ts +8 -8
  18. package/src/launchpad/generated/accounts/bondingCurve.ts +39 -2
  19. package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
  20. package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
  21. package/src/launchpad/generated/index.ts +1 -0
  22. package/src/launchpad/generated/shared/index.ts +52 -0
  23. package/src/launchpad/migrate.ts +1 -1
  24. package/src/launchpad/trade.ts +15 -15
  25. package/src/math/amm.ts +40 -33
  26. package/src/math/fee-decay.ts +3 -2
  27. package/src/math/fees.ts +4 -2
  28. package/src/math/internal.ts +1 -1
  29. package/src/nexus/fee-helpers.ts +5 -3
  30. package/src/nexus/generated/accounts/altRegistry.ts +41 -2
  31. package/src/nexus/generated/accounts/creatorFeeConfig.ts +39 -2
  32. package/src/nexus/generated/accounts/feePreset.ts +41 -2
  33. package/src/nexus/generated/accounts/globalConfig.ts +39 -2
  34. package/src/nexus/generated/accounts/partnerConfig.ts +39 -2
  35. package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
  36. package/src/nexus/generated/accounts/rewardState.ts +41 -2
  37. package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
  38. package/src/nexus/generated/accounts/userRewardDebt.ts +39 -2
  39. package/src/nexus/generated/accounts/userStakePosition.ts +39 -2
  40. package/src/nexus/generated/index.ts +1 -0
  41. package/src/nexus/generated/shared/index.ts +52 -0
  42. package/src/nexus/staking.ts +45 -41
  43. package/src/platform.ts +2 -2
  44. package/src/transfer-fee.ts +19 -17
  45. package/src/utils/chunk.ts +1 -1
  46. package/src/utils/creator-hash.ts +6 -3
  47. package/src/utils/index.ts +2 -0
  48. package/src/utils/mint-info.ts +8 -7
  49. package/src/utils/partner.ts +1 -1
  50. package/src/utils/pda.ts +1 -1
@@ -38,6 +38,7 @@ import {
38
38
  type ReadonlyUint8Array,
39
39
  } from '@solana/kit';
40
40
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
41
+ import { accountIsCreated } from '../shared/index.js';
41
42
 
42
43
  export const ALT_REGISTRY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
43
44
  184, 237, 52, 250, 77, 8, 59, 74,
@@ -97,9 +98,25 @@ export function getAltRegistryCodec(): FixedSizeCodec<
97
98
  return combineCodec(getAltRegistryEncoder(), getAltRegistryDecoder());
98
99
  }
99
100
 
101
+ /**
102
+ * Decodes a `AltRegistry` account, throwing when another program owns it or its discriminator
103
+ * does not match.
104
+ *
105
+ * Unlike {@link fetchMaybeAltRegistry}, this throws for an address that only holds lamports rather
106
+ * than returning the non-existing variant: an account passed as existing must never come back as that
107
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
108
+ */
100
109
  export function decodeAltRegistry<TAddress extends string = string>(
101
110
  encodedAccount: EncodedAccount<TAddress>,
102
111
  ): Account<AltRegistry, TAddress>;
112
+ /**
113
+ * Decodes a `AltRegistry` account, throwing when another program owns it or its discriminator
114
+ * does not match.
115
+ *
116
+ * Unlike {@link fetchMaybeAltRegistry}, this throws for an address that only holds lamports rather
117
+ * than returning the non-existing variant: an account passed as existing must never come back as that
118
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
119
+ */
103
120
  export function decodeAltRegistry<TAddress extends string = string>(
104
121
  encodedAccount: MaybeEncodedAccount<TAddress>,
105
122
  ): MaybeAccount<AltRegistry, TAddress>;
@@ -130,6 +147,7 @@ export function decodeAltRegistry<TAddress extends string = string>(
130
147
  );
131
148
  }
132
149
 
150
+ /** Fetches a `AltRegistry` account, throwing when it does not exist or only holds lamports. */
133
151
  export async function fetchAltRegistry<TAddress extends string = string>(
134
152
  rpc: Parameters<typeof fetchEncodedAccount>[0],
135
153
  address: Address<TAddress>,
@@ -140,15 +158,25 @@ export async function fetchAltRegistry<TAddress extends string = string>(
140
158
  return maybeAccount;
141
159
  }
142
160
 
161
+ /**
162
+ * Fetches a `AltRegistry` account, or the non-existing variant when the address holds no
163
+ * account or only lamports (see {@link accountIsCreated}).
164
+ * {@link decodeAltRegistry} throws for a lamports-only account instead.
165
+ */
143
166
  export async function fetchMaybeAltRegistry<TAddress extends string = string>(
144
167
  rpc: Parameters<typeof fetchEncodedAccount>[0],
145
168
  address: Address<TAddress>,
146
169
  config?: FetchAccountConfig,
147
170
  ): Promise<MaybeAccount<AltRegistry, TAddress>> {
148
171
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
149
- return decodeAltRegistry(maybeAccount);
172
+ return decodeAltRegistry(
173
+ accountIsCreated(maybeAccount)
174
+ ? maybeAccount
175
+ : { address, exists: false },
176
+ );
150
177
  }
151
178
 
179
+ /** Fetches `AltRegistry` accounts, throwing when any does not exist or only holds lamports. */
152
180
  export async function fetchAllAltRegistry(
153
181
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
154
182
  addresses: Array<Address>,
@@ -163,13 +191,24 @@ export async function fetchAllAltRegistry(
163
191
  return maybeAccounts;
164
192
  }
165
193
 
194
+ /**
195
+ * Fetches `AltRegistry` accounts, with the non-existing variant for each address that holds
196
+ * no account or only lamports (see {@link accountIsCreated}).
197
+ * {@link decodeAltRegistry} throws for a lamports-only account instead.
198
+ */
166
199
  export async function fetchAllMaybeAltRegistry(
167
200
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
168
201
  addresses: Array<Address>,
169
202
  config?: FetchAccountsConfig,
170
203
  ): Promise<MaybeAccount<AltRegistry>[]> {
171
204
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
172
- return maybeAccounts.map((maybeAccount) => decodeAltRegistry(maybeAccount));
205
+ return maybeAccounts.map((maybeAccount) =>
206
+ decodeAltRegistry(
207
+ accountIsCreated(maybeAccount)
208
+ ? maybeAccount
209
+ : { address: maybeAccount.address, exists: false },
210
+ ),
211
+ );
173
212
  }
174
213
 
175
214
  export function getAltRegistrySize(): number {
@@ -38,6 +38,7 @@ import {
38
38
  type ReadonlyUint8Array,
39
39
  } from '@solana/kit';
40
40
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
41
+ import { accountIsCreated } from '../shared/index.js';
41
42
 
42
43
  export const CREATOR_FEE_CONFIG_DISCRIMINATOR: ReadonlyUint8Array =
43
44
  new Uint8Array([160, 88, 34, 74, 215, 196, 130, 32]);
@@ -110,9 +111,25 @@ export function getCreatorFeeConfigCodec(): FixedSizeCodec<
110
111
  );
111
112
  }
112
113
 
114
+ /**
115
+ * Decodes a `CreatorFeeConfig` account, throwing when another program owns it or its discriminator
116
+ * does not match.
117
+ *
118
+ * Unlike {@link fetchMaybeCreatorFeeConfig}, this throws for an address that only holds lamports rather
119
+ * than returning the non-existing variant: an account passed as existing must never come back as that
120
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
121
+ */
113
122
  export function decodeCreatorFeeConfig<TAddress extends string = string>(
114
123
  encodedAccount: EncodedAccount<TAddress>,
115
124
  ): Account<CreatorFeeConfig, TAddress>;
125
+ /**
126
+ * Decodes a `CreatorFeeConfig` account, throwing when another program owns it or its discriminator
127
+ * does not match.
128
+ *
129
+ * Unlike {@link fetchMaybeCreatorFeeConfig}, this throws for an address that only holds lamports rather
130
+ * than returning the non-existing variant: an account passed as existing must never come back as that
131
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
132
+ */
116
133
  export function decodeCreatorFeeConfig<TAddress extends string = string>(
117
134
  encodedAccount: MaybeEncodedAccount<TAddress>,
118
135
  ): MaybeAccount<CreatorFeeConfig, TAddress>;
@@ -149,6 +166,7 @@ export function decodeCreatorFeeConfig<TAddress extends string = string>(
149
166
  );
150
167
  }
151
168
 
169
+ /** Fetches a `CreatorFeeConfig` account, throwing when it does not exist or only holds lamports. */
152
170
  export async function fetchCreatorFeeConfig<TAddress extends string = string>(
153
171
  rpc: Parameters<typeof fetchEncodedAccount>[0],
154
172
  address: Address<TAddress>,
@@ -159,6 +177,11 @@ export async function fetchCreatorFeeConfig<TAddress extends string = string>(
159
177
  return maybeAccount;
160
178
  }
161
179
 
180
+ /**
181
+ * Fetches a `CreatorFeeConfig` account, or the non-existing variant when the address holds no
182
+ * account or only lamports (see {@link accountIsCreated}).
183
+ * {@link decodeCreatorFeeConfig} throws for a lamports-only account instead.
184
+ */
162
185
  export async function fetchMaybeCreatorFeeConfig<
163
186
  TAddress extends string = string,
164
187
  >(
@@ -167,9 +190,14 @@ export async function fetchMaybeCreatorFeeConfig<
167
190
  config?: FetchAccountConfig,
168
191
  ): Promise<MaybeAccount<CreatorFeeConfig, TAddress>> {
169
192
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
170
- return decodeCreatorFeeConfig(maybeAccount);
193
+ return decodeCreatorFeeConfig(
194
+ accountIsCreated(maybeAccount)
195
+ ? maybeAccount
196
+ : { address, exists: false },
197
+ );
171
198
  }
172
199
 
200
+ /** Fetches `CreatorFeeConfig` accounts, throwing when any does not exist or only holds lamports. */
173
201
  export async function fetchAllCreatorFeeConfig(
174
202
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
175
203
  addresses: Array<Address>,
@@ -184,6 +212,11 @@ export async function fetchAllCreatorFeeConfig(
184
212
  return maybeAccounts;
185
213
  }
186
214
 
215
+ /**
216
+ * Fetches `CreatorFeeConfig` accounts, with the non-existing variant for each address that holds
217
+ * no account or only lamports (see {@link accountIsCreated}).
218
+ * {@link decodeCreatorFeeConfig} throws for a lamports-only account instead.
219
+ */
187
220
  export async function fetchAllMaybeCreatorFeeConfig(
188
221
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
189
222
  addresses: Array<Address>,
@@ -191,7 +224,11 @@ export async function fetchAllMaybeCreatorFeeConfig(
191
224
  ): Promise<MaybeAccount<CreatorFeeConfig>[]> {
192
225
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
193
226
  return maybeAccounts.map((maybeAccount) =>
194
- decodeCreatorFeeConfig(maybeAccount),
227
+ decodeCreatorFeeConfig(
228
+ accountIsCreated(maybeAccount)
229
+ ? maybeAccount
230
+ : { address: maybeAccount.address, exists: false },
231
+ ),
195
232
  );
196
233
  }
197
234
 
@@ -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
  import {
48
49
  getDexFeesDecoder,
49
50
  getDexFeesEncoder,
@@ -126,9 +127,25 @@ export function getFeePresetCodec(): Codec<FeePresetArgs, FeePreset> {
126
127
  return combineCodec(getFeePresetEncoder(), getFeePresetDecoder());
127
128
  }
128
129
 
130
+ /**
131
+ * Decodes a `FeePreset` account, throwing when another program owns it or its discriminator
132
+ * does not match.
133
+ *
134
+ * Unlike {@link fetchMaybeFeePreset}, 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
+ */
129
138
  export function decodeFeePreset<TAddress extends string = string>(
130
139
  encodedAccount: EncodedAccount<TAddress>,
131
140
  ): Account<FeePreset, TAddress>;
141
+ /**
142
+ * Decodes a `FeePreset` account, throwing when another program owns it or its discriminator
143
+ * does not match.
144
+ *
145
+ * Unlike {@link fetchMaybeFeePreset}, this throws for an address that only holds lamports rather
146
+ * than returning the non-existing variant: an account passed as existing must never come back as that
147
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
148
+ */
132
149
  export function decodeFeePreset<TAddress extends string = string>(
133
150
  encodedAccount: MaybeEncodedAccount<TAddress>,
134
151
  ): MaybeAccount<FeePreset, TAddress>;
@@ -157,6 +174,7 @@ export function decodeFeePreset<TAddress extends string = string>(
157
174
  );
158
175
  }
159
176
 
177
+ /** Fetches a `FeePreset` account, throwing when it does not exist or only holds lamports. */
160
178
  export async function fetchFeePreset<TAddress extends string = string>(
161
179
  rpc: Parameters<typeof fetchEncodedAccount>[0],
162
180
  address: Address<TAddress>,
@@ -167,15 +185,25 @@ export async function fetchFeePreset<TAddress extends string = string>(
167
185
  return maybeAccount;
168
186
  }
169
187
 
188
+ /**
189
+ * Fetches a `FeePreset` account, or the non-existing variant when the address holds no
190
+ * account or only lamports (see {@link accountIsCreated}).
191
+ * {@link decodeFeePreset} throws for a lamports-only account instead.
192
+ */
170
193
  export async function fetchMaybeFeePreset<TAddress extends string = string>(
171
194
  rpc: Parameters<typeof fetchEncodedAccount>[0],
172
195
  address: Address<TAddress>,
173
196
  config?: FetchAccountConfig,
174
197
  ): Promise<MaybeAccount<FeePreset, TAddress>> {
175
198
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
176
- return decodeFeePreset(maybeAccount);
199
+ return decodeFeePreset(
200
+ accountIsCreated(maybeAccount)
201
+ ? maybeAccount
202
+ : { address, exists: false },
203
+ );
177
204
  }
178
205
 
206
+ /** Fetches `FeePreset` accounts, throwing when any does not exist or only holds lamports. */
179
207
  export async function fetchAllFeePreset(
180
208
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
181
209
  addresses: Array<Address>,
@@ -186,11 +214,22 @@ export async function fetchAllFeePreset(
186
214
  return maybeAccounts;
187
215
  }
188
216
 
217
+ /**
218
+ * Fetches `FeePreset` accounts, with the non-existing variant for each address that holds
219
+ * no account or only lamports (see {@link accountIsCreated}).
220
+ * {@link decodeFeePreset} throws for a lamports-only account instead.
221
+ */
189
222
  export async function fetchAllMaybeFeePreset(
190
223
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
191
224
  addresses: Array<Address>,
192
225
  config?: FetchAccountsConfig,
193
226
  ): Promise<MaybeAccount<FeePreset>[]> {
194
227
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
195
- return maybeAccounts.map((maybeAccount) => decodeFeePreset(maybeAccount));
228
+ return maybeAccounts.map((maybeAccount) =>
229
+ decodeFeePreset(
230
+ accountIsCreated(maybeAccount)
231
+ ? maybeAccount
232
+ : { address: maybeAccount.address, exists: false },
233
+ ),
234
+ );
196
235
  }
@@ -40,6 +40,7 @@ import {
40
40
  type ReadonlyUint8Array,
41
41
  } from '@solana/kit';
42
42
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
43
+ import { accountIsCreated } from '../shared/index.js';
43
44
  import {
44
45
  getAuthPlatformEntryDecoder,
45
46
  getAuthPlatformEntryEncoder,
@@ -110,9 +111,25 @@ export function getGlobalConfigCodec(): Codec<GlobalConfigArgs, GlobalConfig> {
110
111
  return combineCodec(getGlobalConfigEncoder(), getGlobalConfigDecoder());
111
112
  }
112
113
 
114
+ /**
115
+ * Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
116
+ * does not match.
117
+ *
118
+ * Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
119
+ * than returning the non-existing variant: an account passed as existing must never come back as that
120
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
121
+ */
113
122
  export function decodeGlobalConfig<TAddress extends string = string>(
114
123
  encodedAccount: EncodedAccount<TAddress>,
115
124
  ): Account<GlobalConfig, TAddress>;
125
+ /**
126
+ * Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
127
+ * does not match.
128
+ *
129
+ * Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
130
+ * than returning the non-existing variant: an account passed as existing must never come back as that
131
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
132
+ */
116
133
  export function decodeGlobalConfig<TAddress extends string = string>(
117
134
  encodedAccount: MaybeEncodedAccount<TAddress>,
118
135
  ): MaybeAccount<GlobalConfig, TAddress>;
@@ -143,6 +160,7 @@ export function decodeGlobalConfig<TAddress extends string = string>(
143
160
  );
144
161
  }
145
162
 
163
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
146
164
  export async function fetchGlobalConfig<TAddress extends string = string>(
147
165
  rpc: Parameters<typeof fetchEncodedAccount>[0],
148
166
  address: Address<TAddress>,
@@ -153,15 +171,25 @@ export async function fetchGlobalConfig<TAddress extends string = string>(
153
171
  return maybeAccount;
154
172
  }
155
173
 
174
+ /**
175
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
176
+ * account or only lamports (see {@link accountIsCreated}).
177
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
178
+ */
156
179
  export async function fetchMaybeGlobalConfig<TAddress extends string = string>(
157
180
  rpc: Parameters<typeof fetchEncodedAccount>[0],
158
181
  address: Address<TAddress>,
159
182
  config?: FetchAccountConfig,
160
183
  ): Promise<MaybeAccount<GlobalConfig, TAddress>> {
161
184
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
162
- return decodeGlobalConfig(maybeAccount);
185
+ return decodeGlobalConfig(
186
+ accountIsCreated(maybeAccount)
187
+ ? maybeAccount
188
+ : { address, exists: false },
189
+ );
163
190
  }
164
191
 
192
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
165
193
  export async function fetchAllGlobalConfig(
166
194
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
167
195
  addresses: Array<Address>,
@@ -176,6 +204,11 @@ export async function fetchAllGlobalConfig(
176
204
  return maybeAccounts;
177
205
  }
178
206
 
207
+ /**
208
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
209
+ * no account or only lamports (see {@link accountIsCreated}).
210
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
211
+ */
179
212
  export async function fetchAllMaybeGlobalConfig(
180
213
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
181
214
  addresses: Array<Address>,
@@ -183,6 +216,10 @@ export async function fetchAllMaybeGlobalConfig(
183
216
  ): Promise<MaybeAccount<GlobalConfig>[]> {
184
217
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
185
218
  return maybeAccounts.map((maybeAccount) =>
186
- decodeGlobalConfig(maybeAccount),
219
+ decodeGlobalConfig(
220
+ accountIsCreated(maybeAccount)
221
+ ? maybeAccount
222
+ : { address: maybeAccount.address, exists: false },
223
+ ),
187
224
  );
188
225
  }
@@ -38,6 +38,7 @@ import {
38
38
  type ReadonlyUint8Array,
39
39
  } from '@solana/kit';
40
40
  import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
41
+ import { accountIsCreated } from '../shared/index.js';
41
42
  import {
42
43
  getDexFeesDecoder,
43
44
  getDexFeesEncoder,
@@ -127,9 +128,25 @@ export function getPartnerConfigCodec(): FixedSizeCodec<
127
128
  return combineCodec(getPartnerConfigEncoder(), getPartnerConfigDecoder());
128
129
  }
129
130
 
131
+ /**
132
+ * Decodes a `PartnerConfig` account, throwing when another program owns it or its discriminator
133
+ * does not match.
134
+ *
135
+ * Unlike {@link fetchMaybePartnerConfig}, this throws for an address that only holds lamports rather
136
+ * than returning the non-existing variant: an account passed as existing must never come back as that
137
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
138
+ */
130
139
  export function decodePartnerConfig<TAddress extends string = string>(
131
140
  encodedAccount: EncodedAccount<TAddress>,
132
141
  ): Account<PartnerConfig, TAddress>;
142
+ /**
143
+ * Decodes a `PartnerConfig` account, throwing when another program owns it or its discriminator
144
+ * does not match.
145
+ *
146
+ * Unlike {@link fetchMaybePartnerConfig}, this throws for an address that only holds lamports rather
147
+ * than returning the non-existing variant: an account passed as existing must never come back as that
148
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
149
+ */
133
150
  export function decodePartnerConfig<TAddress extends string = string>(
134
151
  encodedAccount: MaybeEncodedAccount<TAddress>,
135
152
  ): MaybeAccount<PartnerConfig, TAddress>;
@@ -160,6 +177,7 @@ export function decodePartnerConfig<TAddress extends string = string>(
160
177
  );
161
178
  }
162
179
 
180
+ /** Fetches a `PartnerConfig` account, throwing when it does not exist or only holds lamports. */
163
181
  export async function fetchPartnerConfig<TAddress extends string = string>(
164
182
  rpc: Parameters<typeof fetchEncodedAccount>[0],
165
183
  address: Address<TAddress>,
@@ -170,15 +188,25 @@ export async function fetchPartnerConfig<TAddress extends string = string>(
170
188
  return maybeAccount;
171
189
  }
172
190
 
191
+ /**
192
+ * Fetches a `PartnerConfig` account, or the non-existing variant when the address holds no
193
+ * account or only lamports (see {@link accountIsCreated}).
194
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
195
+ */
173
196
  export async function fetchMaybePartnerConfig<TAddress extends string = string>(
174
197
  rpc: Parameters<typeof fetchEncodedAccount>[0],
175
198
  address: Address<TAddress>,
176
199
  config?: FetchAccountConfig,
177
200
  ): Promise<MaybeAccount<PartnerConfig, TAddress>> {
178
201
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
179
- return decodePartnerConfig(maybeAccount);
202
+ return decodePartnerConfig(
203
+ accountIsCreated(maybeAccount)
204
+ ? maybeAccount
205
+ : { address, exists: false },
206
+ );
180
207
  }
181
208
 
209
+ /** Fetches `PartnerConfig` accounts, throwing when any does not exist or only holds lamports. */
182
210
  export async function fetchAllPartnerConfig(
183
211
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
184
212
  addresses: Array<Address>,
@@ -193,6 +221,11 @@ export async function fetchAllPartnerConfig(
193
221
  return maybeAccounts;
194
222
  }
195
223
 
224
+ /**
225
+ * Fetches `PartnerConfig` accounts, with the non-existing variant for each address that holds
226
+ * no account or only lamports (see {@link accountIsCreated}).
227
+ * {@link decodePartnerConfig} throws for a lamports-only account instead.
228
+ */
196
229
  export async function fetchAllMaybePartnerConfig(
197
230
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
198
231
  addresses: Array<Address>,
@@ -200,7 +233,11 @@ export async function fetchAllMaybePartnerConfig(
200
233
  ): Promise<MaybeAccount<PartnerConfig>[]> {
201
234
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
202
235
  return maybeAccounts.map((maybeAccount) =>
203
- decodePartnerConfig(maybeAccount),
236
+ decodePartnerConfig(
237
+ accountIsCreated(maybeAccount)
238
+ ? maybeAccount
239
+ : { address: maybeAccount.address, exists: false },
240
+ ),
204
241
  );
205
242
  }
206
243
 
@@ -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 {