@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@send-fun/sdk",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Kit-native TypeScript SDK for send.fun",
5
5
  "keywords": [
6
6
  "dex",
@@ -45,12 +45,12 @@
45
45
  "devDependencies": {
46
46
  "@solana-program/token-2022": "^0.9.0",
47
47
  "@solana/kit": "6.10.0",
48
- "@types/node": "^24.10.4",
49
- "@typescript/native-preview": "7.0.0-dev.20260512.1",
50
- "oxfmt": "^0.49.0",
48
+ "@types/node": "^24.13.6",
49
+ "@typescript/native": "npm:typescript@^7.0.2",
50
+ "oxfmt": "^0.70.0",
51
51
  "tsdown": "^0.23.0",
52
- "tsx": "^4.21.0",
53
- "typescript": "^6.0.3"
52
+ "tsx": "^4.23.15",
53
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@solana/kit": "^6.10.0 || ^7.0.0 || ^8.0.0"
@@ -65,7 +65,7 @@
65
65
  "format": "oxfmt --write",
66
66
  "format:check": "oxfmt --check",
67
67
  "test": "tsx --test 'tests/**/*.test.ts'",
68
- "typecheck": "tsgo && tsgo -p compat/tsconfig.json"
68
+ "typecheck": "tsc && tsc -p compat/tsconfig.json"
69
69
  },
70
70
  "types": "./dist/index.d.cts"
71
71
  }
@@ -40,6 +40,7 @@ import {
40
40
  type ReadonlyUint8Array,
41
41
  } from '@solana/kit';
42
42
  import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
43
+ import { accountIsCreated } from '../shared/index.js';
43
44
 
44
45
  export const GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
45
46
  149, 8, 156, 202, 160, 252, 176, 217,
@@ -107,9 +108,25 @@ export function getGlobalConfigCodec(): FixedSizeCodec<
107
108
  return combineCodec(getGlobalConfigEncoder(), getGlobalConfigDecoder());
108
109
  }
109
110
 
111
+ /**
112
+ * Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
113
+ * does not match.
114
+ *
115
+ * Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
116
+ * than returning the non-existing variant: an account passed as existing must never come back as that
117
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
118
+ */
110
119
  export function decodeGlobalConfig<TAddress extends string = string>(
111
120
  encodedAccount: EncodedAccount<TAddress>,
112
121
  ): Account<GlobalConfig, TAddress>;
122
+ /**
123
+ * Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
124
+ * does not match.
125
+ *
126
+ * Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
127
+ * than returning the non-existing variant: an account passed as existing must never come back as that
128
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
129
+ */
113
130
  export function decodeGlobalConfig<TAddress extends string = string>(
114
131
  encodedAccount: MaybeEncodedAccount<TAddress>,
115
132
  ): MaybeAccount<GlobalConfig, TAddress>;
@@ -140,6 +157,7 @@ export function decodeGlobalConfig<TAddress extends string = string>(
140
157
  );
141
158
  }
142
159
 
160
+ /** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
143
161
  export async function fetchGlobalConfig<TAddress extends string = string>(
144
162
  rpc: Parameters<typeof fetchEncodedAccount>[0],
145
163
  address: Address<TAddress>,
@@ -150,15 +168,25 @@ export async function fetchGlobalConfig<TAddress extends string = string>(
150
168
  return maybeAccount;
151
169
  }
152
170
 
171
+ /**
172
+ * Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
173
+ * account or only lamports (see {@link accountIsCreated}).
174
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
175
+ */
153
176
  export async function fetchMaybeGlobalConfig<TAddress extends string = string>(
154
177
  rpc: Parameters<typeof fetchEncodedAccount>[0],
155
178
  address: Address<TAddress>,
156
179
  config?: FetchAccountConfig,
157
180
  ): Promise<MaybeAccount<GlobalConfig, TAddress>> {
158
181
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
159
- return decodeGlobalConfig(maybeAccount);
182
+ return decodeGlobalConfig(
183
+ accountIsCreated(maybeAccount)
184
+ ? maybeAccount
185
+ : { address, exists: false },
186
+ );
160
187
  }
161
188
 
189
+ /** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
162
190
  export async function fetchAllGlobalConfig(
163
191
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
164
192
  addresses: Array<Address>,
@@ -173,6 +201,11 @@ export async function fetchAllGlobalConfig(
173
201
  return maybeAccounts;
174
202
  }
175
203
 
204
+ /**
205
+ * Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
206
+ * no account or only lamports (see {@link accountIsCreated}).
207
+ * {@link decodeGlobalConfig} throws for a lamports-only account instead.
208
+ */
176
209
  export async function fetchAllMaybeGlobalConfig(
177
210
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
178
211
  addresses: Array<Address>,
@@ -180,7 +213,11 @@ export async function fetchAllMaybeGlobalConfig(
180
213
  ): Promise<MaybeAccount<GlobalConfig>[]> {
181
214
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
182
215
  return maybeAccounts.map((maybeAccount) =>
183
- decodeGlobalConfig(maybeAccount),
216
+ decodeGlobalConfig(
217
+ accountIsCreated(maybeAccount)
218
+ ? maybeAccount
219
+ : { address: maybeAccount.address, exists: false },
220
+ ),
184
221
  );
185
222
  }
186
223
 
@@ -18,12 +18,16 @@ import {
18
18
  fixEncoderSize,
19
19
  getAddressDecoder,
20
20
  getAddressEncoder,
21
+ getArrayDecoder,
22
+ getArrayEncoder,
21
23
  getBytesDecoder,
22
24
  getBytesEncoder,
23
25
  getI64Decoder,
24
26
  getI64Encoder,
25
27
  getStructDecoder,
26
28
  getStructEncoder,
29
+ getU16Decoder,
30
+ getU16Encoder,
27
31
  getU64Decoder,
28
32
  getU64Encoder,
29
33
  getU8Decoder,
@@ -42,6 +46,7 @@ import {
42
46
  type ReadonlyUint8Array,
43
47
  } from '@solana/kit';
44
48
  import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
49
+ import { accountIsCreated } from '../shared/index.js';
45
50
  import {
46
51
  getPoolStatusDecoder,
47
52
  getPoolStatusEncoder,
@@ -67,7 +72,7 @@ export type Pool = {
67
72
  quoteMint: Address;
68
73
  quoteDecimals: number;
69
74
  coinCreator: Address;
70
- creatorFeeConfig: Address;
75
+ padding0: Array<bigint>;
71
76
  baseVault: Address;
72
77
  quoteVault: Address;
73
78
  lpMint: Address;
@@ -79,6 +84,8 @@ export type Pool = {
79
84
  protocolOwed: bigint;
80
85
  creatorOwed: bigint;
81
86
  platformConfig: Address;
87
+ creatorFeeMode: number;
88
+ creatorFeeBps: number;
82
89
  reserved: ReadonlyUint8Array;
83
90
  };
84
91
 
@@ -91,7 +98,7 @@ export type PoolArgs = {
91
98
  quoteMint: Address;
92
99
  quoteDecimals: number;
93
100
  coinCreator: Address;
94
- creatorFeeConfig: Address;
101
+ padding0: Array<number | bigint>;
95
102
  baseVault: Address;
96
103
  quoteVault: Address;
97
104
  lpMint: Address;
@@ -103,6 +110,8 @@ export type PoolArgs = {
103
110
  protocolOwed: number | bigint;
104
111
  creatorOwed: number | bigint;
105
112
  platformConfig: Address;
113
+ creatorFeeMode: number;
114
+ creatorFeeBps: number;
106
115
  reserved: ReadonlyUint8Array;
107
116
  };
108
117
 
@@ -119,7 +128,7 @@ export function getPoolEncoder(): FixedSizeEncoder<PoolArgs> {
119
128
  ['quoteMint', getAddressEncoder()],
120
129
  ['quoteDecimals', getU8Encoder()],
121
130
  ['coinCreator', getAddressEncoder()],
122
- ['creatorFeeConfig', getAddressEncoder()],
131
+ ['padding0', getArrayEncoder(getU64Encoder(), { size: 4 })],
123
132
  ['baseVault', getAddressEncoder()],
124
133
  ['quoteVault', getAddressEncoder()],
125
134
  ['lpMint', getAddressEncoder()],
@@ -131,7 +140,9 @@ export function getPoolEncoder(): FixedSizeEncoder<PoolArgs> {
131
140
  ['protocolOwed', getU64Encoder()],
132
141
  ['creatorOwed', getU64Encoder()],
133
142
  ['platformConfig', getAddressEncoder()],
134
- ['reserved', fixEncoderSize(getBytesEncoder(), 64)],
143
+ ['creatorFeeMode', getU8Encoder()],
144
+ ['creatorFeeBps', getU16Encoder()],
145
+ ['reserved', fixEncoderSize(getBytesEncoder(), 256)],
135
146
  ]),
136
147
  (value) => ({ ...value, discriminator: POOL_DISCRIMINATOR }),
137
148
  );
@@ -149,7 +160,7 @@ export function getPoolDecoder(): FixedSizeDecoder<Pool> {
149
160
  ['quoteMint', getAddressDecoder()],
150
161
  ['quoteDecimals', getU8Decoder()],
151
162
  ['coinCreator', getAddressDecoder()],
152
- ['creatorFeeConfig', getAddressDecoder()],
163
+ ['padding0', getArrayDecoder(getU64Decoder(), { size: 4 })],
153
164
  ['baseVault', getAddressDecoder()],
154
165
  ['quoteVault', getAddressDecoder()],
155
166
  ['lpMint', getAddressDecoder()],
@@ -161,7 +172,9 @@ export function getPoolDecoder(): FixedSizeDecoder<Pool> {
161
172
  ['protocolOwed', getU64Decoder()],
162
173
  ['creatorOwed', getU64Decoder()],
163
174
  ['platformConfig', getAddressDecoder()],
164
- ['reserved', fixDecoderSize(getBytesDecoder(), 64)],
175
+ ['creatorFeeMode', getU8Decoder()],
176
+ ['creatorFeeBps', getU16Decoder()],
177
+ ['reserved', fixDecoderSize(getBytesDecoder(), 256)],
165
178
  ]);
166
179
  }
167
180
 
@@ -170,9 +183,25 @@ export function getPoolCodec(): FixedSizeCodec<PoolArgs, Pool> {
170
183
  return combineCodec(getPoolEncoder(), getPoolDecoder());
171
184
  }
172
185
 
186
+ /**
187
+ * Decodes a `Pool` account, throwing when another program owns it or its discriminator
188
+ * does not match.
189
+ *
190
+ * Unlike {@link fetchMaybePool}, this throws for an address that only holds lamports rather
191
+ * than returning the non-existing variant: an account passed as existing must never come back as that
192
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
193
+ */
173
194
  export function decodePool<TAddress extends string = string>(
174
195
  encodedAccount: EncodedAccount<TAddress>,
175
196
  ): Account<Pool, TAddress>;
197
+ /**
198
+ * Decodes a `Pool` account, throwing when another program owns it or its discriminator
199
+ * does not match.
200
+ *
201
+ * Unlike {@link fetchMaybePool}, this throws for an address that only holds lamports rather
202
+ * than returning the non-existing variant: an account passed as existing must never come back as that
203
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
204
+ */
176
205
  export function decodePool<TAddress extends string = string>(
177
206
  encodedAccount: MaybeEncodedAccount<TAddress>,
178
207
  ): MaybeAccount<Pool, TAddress>;
@@ -201,6 +230,7 @@ export function decodePool<TAddress extends string = string>(
201
230
  );
202
231
  }
203
232
 
233
+ /** Fetches a `Pool` account, throwing when it does not exist or only holds lamports. */
204
234
  export async function fetchPool<TAddress extends string = string>(
205
235
  rpc: Parameters<typeof fetchEncodedAccount>[0],
206
236
  address: Address<TAddress>,
@@ -211,15 +241,25 @@ export async function fetchPool<TAddress extends string = string>(
211
241
  return maybeAccount;
212
242
  }
213
243
 
244
+ /**
245
+ * Fetches a `Pool` account, or the non-existing variant when the address holds no
246
+ * account or only lamports (see {@link accountIsCreated}).
247
+ * {@link decodePool} throws for a lamports-only account instead.
248
+ */
214
249
  export async function fetchMaybePool<TAddress extends string = string>(
215
250
  rpc: Parameters<typeof fetchEncodedAccount>[0],
216
251
  address: Address<TAddress>,
217
252
  config?: FetchAccountConfig,
218
253
  ): Promise<MaybeAccount<Pool, TAddress>> {
219
254
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
220
- return decodePool(maybeAccount);
255
+ return decodePool(
256
+ accountIsCreated(maybeAccount)
257
+ ? maybeAccount
258
+ : { address, exists: false },
259
+ );
221
260
  }
222
261
 
262
+ /** Fetches `Pool` accounts, throwing when any does not exist or only holds lamports. */
223
263
  export async function fetchAllPool(
224
264
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
225
265
  addresses: Array<Address>,
@@ -230,15 +270,26 @@ export async function fetchAllPool(
230
270
  return maybeAccounts;
231
271
  }
232
272
 
273
+ /**
274
+ * Fetches `Pool` accounts, with the non-existing variant for each address that holds
275
+ * no account or only lamports (see {@link accountIsCreated}).
276
+ * {@link decodePool} throws for a lamports-only account instead.
277
+ */
233
278
  export async function fetchAllMaybePool(
234
279
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
235
280
  addresses: Array<Address>,
236
281
  config?: FetchAccountsConfig,
237
282
  ): Promise<MaybeAccount<Pool>[]> {
238
283
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
239
- return maybeAccounts.map((maybeAccount) => decodePool(maybeAccount));
284
+ return maybeAccounts.map((maybeAccount) =>
285
+ decodePool(
286
+ accountIsCreated(maybeAccount)
287
+ ? maybeAccount
288
+ : { address: maybeAccount.address, exists: false },
289
+ ),
290
+ );
240
291
  }
241
292
 
242
293
  export function getPoolSize(): number {
243
- return 389;
294
+ return 584;
244
295
  }
@@ -42,6 +42,7 @@ import {
42
42
  type ReadonlyUint8Array,
43
43
  } from '@solana/kit';
44
44
  import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
45
+ import { accountIsCreated } from '../shared/index.js';
45
46
 
46
47
  export const REWARD_ACCRUAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
47
48
  158, 244, 116, 30, 227, 132, 105, 182,
@@ -109,9 +110,25 @@ export function getRewardAccrualCodec(): FixedSizeCodec<
109
110
  return combineCodec(getRewardAccrualEncoder(), getRewardAccrualDecoder());
110
111
  }
111
112
 
113
+ /**
114
+ * Decodes a `RewardAccrual` account, throwing when another program owns it or its discriminator
115
+ * does not match.
116
+ *
117
+ * Unlike {@link fetchMaybeRewardAccrual}, this throws for an address that only holds lamports rather
118
+ * than returning the non-existing variant: an account passed as existing must never come back as that
119
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
120
+ */
112
121
  export function decodeRewardAccrual<TAddress extends string = string>(
113
122
  encodedAccount: EncodedAccount<TAddress>,
114
123
  ): Account<RewardAccrual, TAddress>;
124
+ /**
125
+ * Decodes a `RewardAccrual` account, throwing when another program owns it or its discriminator
126
+ * does not match.
127
+ *
128
+ * Unlike {@link fetchMaybeRewardAccrual}, this throws for an address that only holds lamports rather
129
+ * than returning the non-existing variant: an account passed as existing must never come back as that
130
+ * variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
131
+ */
115
132
  export function decodeRewardAccrual<TAddress extends string = string>(
116
133
  encodedAccount: MaybeEncodedAccount<TAddress>,
117
134
  ): MaybeAccount<RewardAccrual, TAddress>;
@@ -142,6 +159,7 @@ export function decodeRewardAccrual<TAddress extends string = string>(
142
159
  );
143
160
  }
144
161
 
162
+ /** Fetches a `RewardAccrual` account, throwing when it does not exist or only holds lamports. */
145
163
  export async function fetchRewardAccrual<TAddress extends string = string>(
146
164
  rpc: Parameters<typeof fetchEncodedAccount>[0],
147
165
  address: Address<TAddress>,
@@ -152,15 +170,25 @@ export async function fetchRewardAccrual<TAddress extends string = string>(
152
170
  return maybeAccount;
153
171
  }
154
172
 
173
+ /**
174
+ * Fetches a `RewardAccrual` account, or the non-existing variant when the address holds no
175
+ * account or only lamports (see {@link accountIsCreated}).
176
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
177
+ */
155
178
  export async function fetchMaybeRewardAccrual<TAddress extends string = string>(
156
179
  rpc: Parameters<typeof fetchEncodedAccount>[0],
157
180
  address: Address<TAddress>,
158
181
  config?: FetchAccountConfig,
159
182
  ): Promise<MaybeAccount<RewardAccrual, TAddress>> {
160
183
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
161
- return decodeRewardAccrual(maybeAccount);
184
+ return decodeRewardAccrual(
185
+ accountIsCreated(maybeAccount)
186
+ ? maybeAccount
187
+ : { address, exists: false },
188
+ );
162
189
  }
163
190
 
191
+ /** Fetches `RewardAccrual` accounts, throwing when any does not exist or only holds lamports. */
164
192
  export async function fetchAllRewardAccrual(
165
193
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
166
194
  addresses: Array<Address>,
@@ -175,6 +203,11 @@ export async function fetchAllRewardAccrual(
175
203
  return maybeAccounts;
176
204
  }
177
205
 
206
+ /**
207
+ * Fetches `RewardAccrual` accounts, with the non-existing variant for each address that holds
208
+ * no account or only lamports (see {@link accountIsCreated}).
209
+ * {@link decodeRewardAccrual} throws for a lamports-only account instead.
210
+ */
178
211
  export async function fetchAllMaybeRewardAccrual(
179
212
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
180
213
  addresses: Array<Address>,
@@ -182,7 +215,11 @@ export async function fetchAllMaybeRewardAccrual(
182
215
  ): Promise<MaybeAccount<RewardAccrual>[]> {
183
216
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
184
217
  return maybeAccounts.map((maybeAccount) =>
185
- decodeRewardAccrual(maybeAccount),
218
+ decodeRewardAccrual(
219
+ accountIsCreated(maybeAccount)
220
+ ? maybeAccount
221
+ : { address: maybeAccount.address, exists: false },
222
+ ),
186
223
  );
187
224
  }
188
225
 
@@ -36,8 +36,8 @@ export const SEND_DEX_ERROR__INVALID_POOL_BALANCE = 0x1778; // 6008
36
36
  export const SEND_DEX_ERROR__INSUFFICIENT_POOL_BALANCE = 0x1779; // 6009
37
37
  /** InvalidAuthority: Invalid authority */
38
38
  export const SEND_DEX_ERROR__INVALID_AUTHORITY = 0x177a; // 6010
39
- /** InvalidCreatorHash: creator_hash does not match (creator_platform, creator_id) */
40
- export const SEND_DEX_ERROR__INVALID_CREATOR_HASH = 0x177b; // 6011
39
+ /** InvalidCoinCreator: Invalid coin creator */
40
+ export const SEND_DEX_ERROR__INVALID_COIN_CREATOR = 0x177b; // 6011
41
41
  /** InvalidPlatformConfig: Platform config cannot be the default address */
42
42
  export const SEND_DEX_ERROR__INVALID_PLATFORM_CONFIG = 0x177c; // 6012
43
43
  /** ProgramPaused: Program is paused */
@@ -64,12 +64,16 @@ export const SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT = 0x1b61; // 7009
64
64
  export const SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY = 0x1b62; // 7010
65
65
  /** NothingToClaim: Nothing to claim */
66
66
  export const SEND_DEX_ERROR__NOTHING_TO_CLAIM = 0x1b63; // 7011
67
- /** InvalidCreatorId: Creator identity is not a decodable wallet address */
68
- export const SEND_DEX_ERROR__INVALID_CREATOR_ID = 0x1b64; // 7012
67
+ /** Unused7012: Unused */
68
+ export const SEND_DEX_ERROR__UNUSED7012 = 0x1b64; // 7012
69
69
  /** QuoteMintPriceUnset: Quote mint has no USDC price on its nexus reward state */
70
70
  export const SEND_DEX_ERROR__QUOTE_MINT_PRICE_UNSET = 0x1b65; // 7013
71
71
  /** TransferFeeNotSettleable: Token-2022 transfer fee schedule cannot settle the exact amount */
72
72
  export const SEND_DEX_ERROR__TRANSFER_FEE_NOT_SETTLEABLE = 0x1b66; // 7014
73
+ /** CreatorFeeTooHigh: Creator fee exceeds the partner's maximum */
74
+ export const SEND_DEX_ERROR__CREATOR_FEE_TOO_HIGH = 0x1b67; // 7015
75
+ /** CreatorFeeModeNotAllowed: Creator fee mode is not allowed by the partner config */
76
+ export const SEND_DEX_ERROR__CREATOR_FEE_MODE_NOT_ALLOWED = 0x1b68; // 7016
73
77
  /** InsufficientLiquidity: Insufficient liquidity */
74
78
  export const SEND_DEX_ERROR__INSUFFICIENT_LIQUIDITY = 0x1bbc; // 7100
75
79
  /** InvalidAmount: Invalid amount */
@@ -77,14 +81,15 @@ export const SEND_DEX_ERROR__INVALID_AMOUNT = 0x1bbd; // 7101
77
81
 
78
82
  export type SendDexError =
79
83
  | typeof SEND_DEX_ERROR__ARITHMETIC_OVERFLOW
84
+ | typeof SEND_DEX_ERROR__CREATOR_FEE_MODE_NOT_ALLOWED
85
+ | typeof SEND_DEX_ERROR__CREATOR_FEE_TOO_HIGH
80
86
  | typeof SEND_DEX_ERROR__INSUFFICIENT_BALANCE
81
87
  | typeof SEND_DEX_ERROR__INSUFFICIENT_LIQUIDITY
82
88
  | typeof SEND_DEX_ERROR__INSUFFICIENT_POOL_BALANCE
83
89
  | typeof SEND_DEX_ERROR__INVALID_AMOUNT
84
90
  | typeof SEND_DEX_ERROR__INVALID_AUTHORITY
85
91
  | typeof SEND_DEX_ERROR__INVALID_BASE_MINT
86
- | typeof SEND_DEX_ERROR__INVALID_CREATOR_HASH
87
- | typeof SEND_DEX_ERROR__INVALID_CREATOR_ID
92
+ | typeof SEND_DEX_ERROR__INVALID_COIN_CREATOR
88
93
  | typeof SEND_DEX_ERROR__INVALID_DEPOSIT
89
94
  | typeof SEND_DEX_ERROR__INVALID_PLATFORM_CONFIG
90
95
  | typeof SEND_DEX_ERROR__INVALID_POOL_BALANCE
@@ -102,6 +107,7 @@ export type SendDexError =
102
107
  | typeof SEND_DEX_ERROR__TEXT_TOO_LONG
103
108
  | typeof SEND_DEX_ERROR__TRANSFER_FEE_NOT_SETTLEABLE
104
109
  | typeof SEND_DEX_ERROR__UNAUTHORIZED
110
+ | typeof SEND_DEX_ERROR__UNUSED7012
105
111
  | typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_INVALID
106
112
  | typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY
107
113
  | typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT
@@ -109,14 +115,15 @@ export type SendDexError =
109
115
 
110
116
  export const sendDexErrorMessages: Record<SendDexError, string> = {
111
117
  [SEND_DEX_ERROR__ARITHMETIC_OVERFLOW]: `Arithmetic overflow`,
118
+ [SEND_DEX_ERROR__CREATOR_FEE_MODE_NOT_ALLOWED]: `Creator fee mode is not allowed by the partner config`,
119
+ [SEND_DEX_ERROR__CREATOR_FEE_TOO_HIGH]: `Creator fee exceeds the partner's maximum`,
112
120
  [SEND_DEX_ERROR__INSUFFICIENT_BALANCE]: `Insufficient balance in source account`,
113
121
  [SEND_DEX_ERROR__INSUFFICIENT_LIQUIDITY]: `Insufficient liquidity`,
114
122
  [SEND_DEX_ERROR__INSUFFICIENT_POOL_BALANCE]: `Insufficient pool balance`,
115
123
  [SEND_DEX_ERROR__INVALID_AMOUNT]: `Invalid amount`,
116
124
  [SEND_DEX_ERROR__INVALID_AUTHORITY]: `Invalid authority`,
117
125
  [SEND_DEX_ERROR__INVALID_BASE_MINT]: `Invalid base mint`,
118
- [SEND_DEX_ERROR__INVALID_CREATOR_HASH]: `creator_hash does not match (creator_platform, creator_id)`,
119
- [SEND_DEX_ERROR__INVALID_CREATOR_ID]: `Creator identity is not a decodable wallet address`,
126
+ [SEND_DEX_ERROR__INVALID_COIN_CREATOR]: `Invalid coin creator`,
120
127
  [SEND_DEX_ERROR__INVALID_DEPOSIT]: `Invalid deposit`,
121
128
  [SEND_DEX_ERROR__INVALID_PLATFORM_CONFIG]: `Platform config cannot be the default address`,
122
129
  [SEND_DEX_ERROR__INVALID_POOL_BALANCE]: `Invalid pool balance`,
@@ -134,6 +141,7 @@ export const sendDexErrorMessages: Record<SendDexError, string> = {
134
141
  [SEND_DEX_ERROR__TEXT_TOO_LONG]: `Text too long`,
135
142
  [SEND_DEX_ERROR__TRANSFER_FEE_NOT_SETTLEABLE]: `Token-2022 transfer fee schedule cannot settle the exact amount`,
136
143
  [SEND_DEX_ERROR__UNAUTHORIZED]: `Unauthorized`,
144
+ [SEND_DEX_ERROR__UNUSED7012]: `Unused`,
137
145
  [SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_INVALID]: `User token account is not an initialized token account`,
138
146
  [SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY]: `User token account is not owned by the trading user`,
139
147
  [SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT]: `User token account mint does not match the trade`,
@@ -10,6 +10,7 @@ import {
10
10
  containsBytes,
11
11
  fixEncoderSize,
12
12
  getAddressDecoder,
13
+ getArrayDecoder,
13
14
  getBytesEncoder,
14
15
  getI64Decoder,
15
16
  getStructDecoder,
@@ -36,7 +37,7 @@ export type CreatorClaimEvent = {
36
37
  quoteMint: Address;
37
38
  platformConfig: Address;
38
39
  coinCreator: Address;
39
- creatorFeeConfig: Address;
40
+ padding0: Array<bigint>;
40
41
  claimer: Address;
41
42
  destinationOwner: Address;
42
43
  amount: bigint;
@@ -55,7 +56,7 @@ export function getCreatorClaimEventDecoder(): FixedSizeDecoder<CreatorClaimEven
55
56
  ['quoteMint', getAddressDecoder()],
56
57
  ['platformConfig', getAddressDecoder()],
57
58
  ['coinCreator', getAddressDecoder()],
58
- ['creatorFeeConfig', getAddressDecoder()],
59
+ ['padding0', getArrayDecoder(getU64Decoder(), { size: 4 })],
59
60
  ['claimer', getAddressDecoder()],
60
61
  ['destinationOwner', getAddressDecoder()],
61
62
  ['amount', getU64Decoder()],
@@ -10,9 +10,11 @@ import {
10
10
  containsBytes,
11
11
  fixEncoderSize,
12
12
  getAddressDecoder,
13
+ getArrayDecoder,
13
14
  getBytesEncoder,
14
15
  getI64Decoder,
15
16
  getStructDecoder,
17
+ getU16Decoder,
16
18
  getU64Decoder,
17
19
  getU8Decoder,
18
20
  type Address,
@@ -38,7 +40,7 @@ export type PoolCreateEvent = {
38
40
  quoteMint: Address;
39
41
  quoteDecimals: number;
40
42
  coinCreator: Address;
41
- creatorFeeConfig: Address;
43
+ padding0: Array<bigint>;
42
44
  platformConfig: Address;
43
45
  baseVault: Address;
44
46
  quoteVault: Address;
@@ -47,6 +49,8 @@ export type PoolCreateEvent = {
47
49
  baseReserves: bigint;
48
50
  quoteReserves: bigint;
49
51
  timestamp: bigint;
52
+ creatorFeeMode: number;
53
+ creatorFeeBps: number;
50
54
  };
51
55
 
52
56
  let getPoolCreateEventDecoderCache:
@@ -61,7 +65,7 @@ export function getPoolCreateEventDecoder(): FixedSizeDecoder<PoolCreateEvent> {
61
65
  ['quoteMint', getAddressDecoder()],
62
66
  ['quoteDecimals', getU8Decoder()],
63
67
  ['coinCreator', getAddressDecoder()],
64
- ['creatorFeeConfig', getAddressDecoder()],
68
+ ['padding0', getArrayDecoder(getU64Decoder(), { size: 4 })],
65
69
  ['platformConfig', getAddressDecoder()],
66
70
  ['baseVault', getAddressDecoder()],
67
71
  ['quoteVault', getAddressDecoder()],
@@ -70,6 +74,8 @@ export function getPoolCreateEventDecoder(): FixedSizeDecoder<PoolCreateEvent> {
70
74
  ['baseReserves', getU64Decoder()],
71
75
  ['quoteReserves', getU64Decoder()],
72
76
  ['timestamp', getI64Decoder()],
77
+ ['creatorFeeMode', getU8Decoder()],
78
+ ['creatorFeeBps', getU16Decoder()],
73
79
  ]));
74
80
  }
75
81
 
@@ -11,10 +11,12 @@ import {
11
11
  containsBytes,
12
12
  fixEncoderSize,
13
13
  getAddressDecoder,
14
+ getArrayDecoder,
14
15
  getBooleanDecoder,
15
16
  getBytesEncoder,
16
17
  getI64Decoder,
17
18
  getStructDecoder,
19
+ getU16Decoder,
18
20
  getU32Decoder,
19
21
  getU64Decoder,
20
22
  getU8Decoder,
@@ -43,9 +45,7 @@ export type TokenCreateEvent = {
43
45
  quoteMint: Address;
44
46
  quoteDecimals: number;
45
47
  coinCreator: Address;
46
- creatorPlatform: string;
47
- creatorId: string;
48
- creatorFeeConfig: Address;
48
+ padding0: Array<bigint>;
49
49
  platformConfig: Address;
50
50
  name: string;
51
51
  symbol: string;
@@ -56,6 +56,8 @@ export type TokenCreateEvent = {
56
56
  baseReserves: bigint;
57
57
  quoteReserves: bigint;
58
58
  timestamp: bigint;
59
+ creatorFeeMode: number;
60
+ creatorFeeBps: number;
59
61
  };
60
62
 
61
63
  let getTokenCreateEventDecoderCache: Decoder<TokenCreateEvent> | undefined;
@@ -69,12 +71,7 @@ export function getTokenCreateEventDecoder(): Decoder<TokenCreateEvent> {
69
71
  ['quoteMint', getAddressDecoder()],
70
72
  ['quoteDecimals', getU8Decoder()],
71
73
  ['coinCreator', getAddressDecoder()],
72
- [
73
- 'creatorPlatform',
74
- addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()),
75
- ],
76
- ['creatorId', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
77
- ['creatorFeeConfig', getAddressDecoder()],
74
+ ['padding0', getArrayDecoder(getU64Decoder(), { size: 5 })],
78
75
  ['platformConfig', getAddressDecoder()],
79
76
  ['name', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
80
77
  ['symbol', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
@@ -85,6 +82,8 @@ export function getTokenCreateEventDecoder(): Decoder<TokenCreateEvent> {
85
82
  ['baseReserves', getU64Decoder()],
86
83
  ['quoteReserves', getU64Decoder()],
87
84
  ['timestamp', getI64Decoder()],
85
+ ['creatorFeeMode', getU8Decoder()],
86
+ ['creatorFeeBps', getU16Decoder()],
88
87
  ]));
89
88
  }
90
89
 
@@ -10,11 +10,14 @@ import {
10
10
  containsBytes,
11
11
  fixEncoderSize,
12
12
  getAddressDecoder,
13
+ getArrayDecoder,
13
14
  getBooleanDecoder,
14
15
  getBytesEncoder,
15
16
  getI64Decoder,
16
17
  getStructDecoder,
18
+ getU16Decoder,
17
19
  getU64Decoder,
20
+ getU8Decoder,
18
21
  type Address,
19
22
  type FixedSizeDecoder,
20
23
  type ReadonlyUint8Array,
@@ -42,7 +45,7 @@ export type TradeEvent = {
42
45
  quoteMint: Address;
43
46
  user: Address;
44
47
  coinCreator: Address;
45
- creatorFeeConfig: Address;
48
+ padding0: Array<bigint>;
46
49
  platformConfig: Address;
47
50
  baseAmount: bigint;
48
51
  quoteAmountGross: bigint;
@@ -58,6 +61,8 @@ export type TradeEvent = {
58
61
  baseReserves: bigint;
59
62
  quoteReserves: bigint;
60
63
  timestamp: bigint;
64
+ creatorFeeMode: number;
65
+ creatorFeeBps: number;
61
66
  };
62
67
 
63
68
  let getTradeEventDecoderCache: FixedSizeDecoder<TradeEvent> | undefined;
@@ -69,7 +74,7 @@ export function getTradeEventDecoder(): FixedSizeDecoder<TradeEvent> {
69
74
  ['quoteMint', getAddressDecoder()],
70
75
  ['user', getAddressDecoder()],
71
76
  ['coinCreator', getAddressDecoder()],
72
- ['creatorFeeConfig', getAddressDecoder()],
77
+ ['padding0', getArrayDecoder(getU64Decoder(), { size: 4 })],
73
78
  ['platformConfig', getAddressDecoder()],
74
79
  ['baseAmount', getU64Decoder()],
75
80
  ['quoteAmountGross', getU64Decoder()],
@@ -85,6 +90,8 @@ export function getTradeEventDecoder(): FixedSizeDecoder<TradeEvent> {
85
90
  ['baseReserves', getU64Decoder()],
86
91
  ['quoteReserves', getU64Decoder()],
87
92
  ['timestamp', getI64Decoder()],
93
+ ['creatorFeeMode', getU8Decoder()],
94
+ ['creatorFeeBps', getU16Decoder()],
88
95
  ]));
89
96
  }
90
97
 
@@ -13,4 +13,5 @@ export * from './instructions/index.js';
13
13
  export * from './pdas/index.js';
14
14
  export * from './plugins/index.js';
15
15
  export * from './programs/index.js';
16
+ export * from './shared/index.js';
16
17
  export * from './types/index.js';