@send-fun/sdk 1.2.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 (51) hide show
  1. package/dist/index.cjs +281 -365
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +125 -166
  4. package/dist/index.d.cts.map +1 -1
  5. package/dist/index.d.mts +125 -166
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +281 -365
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +7 -7
  10. package/src/dex/generated/accounts/pool.ts +19 -7
  11. package/src/dex/generated/errors/sendDex.ts +16 -8
  12. package/src/dex/generated/events/creatorClaimEvent.ts +3 -2
  13. package/src/dex/generated/events/poolCreateEvent.ts +8 -2
  14. package/src/dex/generated/events/tokenCreateEvent.ts +8 -9
  15. package/src/dex/generated/events/tradeEvent.ts +9 -2
  16. package/src/dex/generated/instructions/claimCreatorFees.ts +21 -5
  17. package/src/{nexus → dex}/generated/pdas/creatorFeeConfig.ts +6 -6
  18. package/src/dex/generated/pdas/index.ts +1 -0
  19. package/src/dex/generated/plugins/sendDex.ts +3 -0
  20. package/src/launchpad/create.ts +9 -34
  21. package/src/launchpad/generated/accounts/bondingCurve.ts +23 -7
  22. package/src/launchpad/generated/errors/sendLaunchpad.ts +12 -4
  23. package/src/launchpad/generated/events/completeEvent.ts +3 -2
  24. package/src/launchpad/generated/events/creatorClaimEvent.ts +3 -2
  25. package/src/launchpad/generated/events/migrateEvent.ts +3 -2
  26. package/src/launchpad/generated/events/tokenCreateEvent.ts +10 -9
  27. package/src/launchpad/generated/events/tradeEvent.ts +9 -2
  28. package/src/launchpad/generated/instructions/claimCreatorFees.ts +17 -4
  29. package/src/launchpad/generated/instructions/createToken.ts +32 -50
  30. package/src/launchpad/generated/instructions/migrate.ts +79 -12
  31. package/src/launchpad/generated/pdas/creatorFeeConfig.ts +39 -0
  32. package/src/launchpad/generated/pdas/index.ts +1 -0
  33. package/src/launchpad/generated/plugins/sendLaunchpad.ts +3 -0
  34. package/src/launchpad/migrate.ts +7 -4
  35. package/src/nexus/fee-helpers.ts +8 -5
  36. package/src/nexus/generated/accounts/feePreset.ts +2 -2
  37. package/src/nexus/generated/accounts/index.ts +0 -1
  38. package/src/nexus/generated/accounts/partnerConfig.ts +9 -3
  39. package/src/nexus/generated/accounts/sendNexus.accounts.ts +0 -5
  40. package/src/nexus/generated/accounts/userRewardDebt.ts +3 -3
  41. package/src/nexus/generated/accounts/userStakePosition.ts +3 -3
  42. package/src/nexus/generated/errors/sendNexus.ts +12 -4
  43. package/src/nexus/generated/pdas/index.ts +0 -1
  44. package/src/nexus/generated/plugins/sendNexus.ts +0 -35
  45. package/src/nexus/generated/types/dexFees.ts +4 -4
  46. package/src/nexus/generated/types/index.ts +0 -1
  47. package/src/nexus/generated/types/launchpadFees.ts +4 -4
  48. package/src/utils/index.ts +0 -5
  49. package/src/nexus/generated/accounts/creatorFeeConfig.ts +0 -237
  50. package/src/nexus/generated/types/callerType.ts +0 -38
  51. package/src/utils/creator-hash.ts +0 -60
@@ -23,11 +23,9 @@ import {
23
23
  } from '@solana/kit/program-client-core';
24
24
  import {
25
25
  fetchAllAltRegistry,
26
- fetchAllCreatorFeeConfig,
27
26
  fetchAllFeePreset,
28
27
  fetchAllGlobalConfig,
29
28
  fetchAllMaybeAltRegistry,
30
- fetchAllMaybeCreatorFeeConfig,
31
29
  fetchAllMaybeFeePreset,
32
30
  fetchAllMaybeGlobalConfig,
33
31
  fetchAllMaybePartnerConfig,
@@ -43,11 +41,9 @@ import {
43
41
  fetchAllUserRewardDebt,
44
42
  fetchAllUserStakePosition,
45
43
  fetchAltRegistry,
46
- fetchCreatorFeeConfig,
47
44
  fetchFeePreset,
48
45
  fetchGlobalConfig,
49
46
  fetchMaybeAltRegistry,
50
- fetchMaybeCreatorFeeConfig,
51
47
  fetchMaybeFeePreset,
52
48
  fetchMaybeGlobalConfig,
53
49
  fetchMaybePartnerConfig,
@@ -63,7 +59,6 @@ import {
63
59
  fetchUserRewardDebt,
64
60
  fetchUserStakePosition,
65
61
  getAltRegistryCodec,
66
- getCreatorFeeConfigCodec,
67
62
  getFeePresetCodec,
68
63
  getGlobalConfigCodec,
69
64
  getPartnerConfigCodec,
@@ -75,8 +70,6 @@ import {
75
70
  identifySendNexusAccount,
76
71
  type AltRegistry,
77
72
  type AltRegistryArgs,
78
- type CreatorFeeConfig,
79
- type CreatorFeeConfigArgs,
80
73
  type FeePreset,
81
74
  type FeePresetArgs,
82
75
  type GlobalConfig,
@@ -115,7 +108,6 @@ import {
115
108
  } from '../instructions/index.js';
116
109
  import {
117
110
  findAltRegistryPda,
118
- findCreatorFeeConfigPda,
119
111
  findDefaultFeePresetPda,
120
112
  findDefaultPartnerMetadataPda,
121
113
  findDefaultPartnerPda,
@@ -143,8 +135,6 @@ export type SendNexusPlugin = {
143
135
  export type SendNexusPluginAccounts = {
144
136
  altRegistry: ReturnType<typeof getAltRegistryCodec> &
145
137
  SelfFetchFunctions<AltRegistryArgs, AltRegistry>;
146
- creatorFeeConfig: ReturnType<typeof getCreatorFeeConfigCodec> &
147
- SelfFetchFunctions<CreatorFeeConfigArgs, CreatorFeeConfig>;
148
138
  feePreset: ReturnType<typeof getFeePresetCodec> &
149
139
  SelfFetchFunctions<FeePresetArgs, FeePreset>;
150
140
  globalConfig: ReturnType<typeof getGlobalConfigCodec> &
@@ -203,7 +193,6 @@ export type SendNexusPluginPdas = {
203
193
  userStakePosition: typeof findUserStakePositionPda;
204
194
  userRewardDebt: typeof findUserRewardDebtPda;
205
195
  eventAuthority: typeof findEventAuthorityPda;
206
- creatorFeeConfig: typeof findCreatorFeeConfigPda;
207
196
  altRegistry: typeof findAltRegistryPda;
208
197
  };
209
198
 
@@ -236,29 +225,6 @@ export function sendNexusProgram() {
236
225
  fetchMaybe: (address, config) =>
237
226
  fetchMaybeAltRegistry(client.rpc, address, config),
238
227
  }),
239
- creatorFeeConfig: Object.freeze({
240
- ...getCreatorFeeConfigCodec(),
241
- fetch: (address, config) =>
242
- fetchCreatorFeeConfig(client.rpc, address, config),
243
- fetchAll: (addresses, config) =>
244
- fetchAllCreatorFeeConfig(
245
- client.rpc,
246
- addresses,
247
- config,
248
- ),
249
- fetchAllMaybe: (addresses, config) =>
250
- fetchAllMaybeCreatorFeeConfig(
251
- client.rpc,
252
- addresses,
253
- config,
254
- ),
255
- fetchMaybe: (address, config) =>
256
- fetchMaybeCreatorFeeConfig(
257
- client.rpc,
258
- address,
259
- config,
260
- ),
261
- }),
262
228
  feePreset: Object.freeze({
263
229
  ...getFeePresetCodec(),
264
230
  fetch: (address, config) =>
@@ -480,7 +446,6 @@ export function sendNexusProgram() {
480
446
  userStakePosition: findUserStakePositionPda,
481
447
  userRewardDebt: findUserRewardDebtPda,
482
448
  eventAuthority: findEventAuthorityPda,
483
- creatorFeeConfig: findCreatorFeeConfigPda,
484
449
  altRegistry: findAltRegistryPda,
485
450
  },
486
451
  identifyAccount: identifySendNexusAccount,
@@ -23,7 +23,7 @@ export type DexFees = {
23
23
  creationFeeCents: bigint;
24
24
  protocolFeeBps: number;
25
25
  lpFeeBps: number;
26
- creatorFeeBps: number;
26
+ maxCreatorFeeBps: number;
27
27
  feeDecaySeconds: number;
28
28
  feeDecayStartBps: number;
29
29
  };
@@ -32,7 +32,7 @@ export type DexFeesArgs = {
32
32
  creationFeeCents: number | bigint;
33
33
  protocolFeeBps: number;
34
34
  lpFeeBps: number;
35
- creatorFeeBps: number;
35
+ maxCreatorFeeBps: number;
36
36
  feeDecaySeconds: number;
37
37
  feeDecayStartBps: number;
38
38
  };
@@ -42,7 +42,7 @@ export function getDexFeesEncoder(): FixedSizeEncoder<DexFeesArgs> {
42
42
  ['creationFeeCents', getU64Encoder()],
43
43
  ['protocolFeeBps', getU16Encoder()],
44
44
  ['lpFeeBps', getU16Encoder()],
45
- ['creatorFeeBps', getU16Encoder()],
45
+ ['maxCreatorFeeBps', getU16Encoder()],
46
46
  ['feeDecaySeconds', getU16Encoder()],
47
47
  ['feeDecayStartBps', getU16Encoder()],
48
48
  ]);
@@ -53,7 +53,7 @@ export function getDexFeesDecoder(): FixedSizeDecoder<DexFees> {
53
53
  ['creationFeeCents', getU64Decoder()],
54
54
  ['protocolFeeBps', getU16Decoder()],
55
55
  ['lpFeeBps', getU16Decoder()],
56
- ['creatorFeeBps', getU16Decoder()],
56
+ ['maxCreatorFeeBps', getU16Decoder()],
57
57
  ['feeDecaySeconds', getU16Decoder()],
58
58
  ['feeDecayStartBps', getU16Decoder()],
59
59
  ]);
@@ -7,7 +7,6 @@
7
7
  */
8
8
 
9
9
  export * from './authPlatformEntry.js';
10
- export * from './callerType.js';
11
10
  export * from './dexFees.js';
12
11
  export * from './feeConfig.js';
13
12
  export * from './launchpadFees.js';
@@ -22,7 +22,7 @@ import {
22
22
  export type LaunchpadFees = {
23
23
  creationFeeCents: bigint;
24
24
  protocolFeeBps: number;
25
- creatorFeeBps: number;
25
+ maxCreatorFeeBps: number;
26
26
  feeDecaySeconds: number;
27
27
  feeDecayStartBps: number;
28
28
  };
@@ -30,7 +30,7 @@ export type LaunchpadFees = {
30
30
  export type LaunchpadFeesArgs = {
31
31
  creationFeeCents: number | bigint;
32
32
  protocolFeeBps: number;
33
- creatorFeeBps: number;
33
+ maxCreatorFeeBps: number;
34
34
  feeDecaySeconds: number;
35
35
  feeDecayStartBps: number;
36
36
  };
@@ -39,7 +39,7 @@ export function getLaunchpadFeesEncoder(): FixedSizeEncoder<LaunchpadFeesArgs> {
39
39
  return getStructEncoder([
40
40
  ['creationFeeCents', getU64Encoder()],
41
41
  ['protocolFeeBps', getU16Encoder()],
42
- ['creatorFeeBps', getU16Encoder()],
42
+ ['maxCreatorFeeBps', getU16Encoder()],
43
43
  ['feeDecaySeconds', getU16Encoder()],
44
44
  ['feeDecayStartBps', getU16Encoder()],
45
45
  ]);
@@ -49,7 +49,7 @@ export function getLaunchpadFeesDecoder(): FixedSizeDecoder<LaunchpadFees> {
49
49
  return getStructDecoder([
50
50
  ['creationFeeCents', getU64Decoder()],
51
51
  ['protocolFeeBps', getU16Decoder()],
52
- ['creatorFeeBps', getU16Decoder()],
52
+ ['maxCreatorFeeBps', getU16Decoder()],
53
53
  ['feeDecaySeconds', getU16Decoder()],
54
54
  ['feeDecayStartBps', getU16Decoder()],
55
55
  ]);
@@ -1,10 +1,5 @@
1
1
  // The three programs generate the same function.
2
2
  export { accountIsCreated } from '../nexus/generated/shared/index.js';
3
- export {
4
- creatorHashFromId,
5
- decodeCreatorId,
6
- encodeCreatorId,
7
- } from './creator-hash.js';
8
3
  export { fetchQuoteMintInfo, fetchQuoteMintInfos } from './mint-info.js';
9
4
  export type { QuoteMintInfo } from './mint-info.js';
10
5
  export type { PartnerInput } from './partner.js';
@@ -1,237 +0,0 @@
1
- /**
2
- * This code was AUTOGENERATED using the Codama library.
3
- * Please DO NOT EDIT THIS FILE, instead use visitors
4
- * to add features, then rerun Codama to update it.
5
- *
6
- * @see https://github.com/codama-idl/codama
7
- */
8
-
9
- import {
10
- assertAccountExists,
11
- assertAccountsExist,
12
- combineCodec,
13
- containsBytes,
14
- decodeAccount,
15
- fetchEncodedAccount,
16
- fetchEncodedAccounts,
17
- fixDecoderSize,
18
- fixEncoderSize,
19
- getAddressDecoder,
20
- getAddressEncoder,
21
- getBytesDecoder,
22
- getBytesEncoder,
23
- getStructDecoder,
24
- getStructEncoder,
25
- getU8Decoder,
26
- getU8Encoder,
27
- transformEncoder,
28
- type Account,
29
- type Address,
30
- type EncodedAccount,
31
- type FetchAccountConfig,
32
- type FetchAccountsConfig,
33
- type FixedSizeCodec,
34
- type FixedSizeDecoder,
35
- type FixedSizeEncoder,
36
- type MaybeAccount,
37
- type MaybeEncodedAccount,
38
- type ReadonlyUint8Array,
39
- } from '@solana/kit';
40
- import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
41
- import { accountIsCreated } from '../shared/index.js';
42
-
43
- export const CREATOR_FEE_CONFIG_DISCRIMINATOR: ReadonlyUint8Array =
44
- new Uint8Array([160, 88, 34, 74, 215, 196, 130, 32]);
45
-
46
- export function getCreatorFeeConfigDiscriminatorBytes(): ReadonlyUint8Array {
47
- return fixEncoderSize(getBytesEncoder(), 8).encode(
48
- CREATOR_FEE_CONFIG_DISCRIMINATOR,
49
- );
50
- }
51
-
52
- export type CreatorFeeConfig = {
53
- discriminator: ReadonlyUint8Array;
54
- version: number;
55
- bump: number;
56
- platformIndex: number;
57
- platformId: ReadonlyUint8Array;
58
- quoteMint: Address;
59
- reserved: ReadonlyUint8Array;
60
- };
61
-
62
- export type CreatorFeeConfigArgs = {
63
- version: number;
64
- bump: number;
65
- platformIndex: number;
66
- platformId: ReadonlyUint8Array;
67
- quoteMint: Address;
68
- reserved: ReadonlyUint8Array;
69
- };
70
-
71
- /** Gets the encoder for {@link CreatorFeeConfigArgs} account data. */
72
- export function getCreatorFeeConfigEncoder(): FixedSizeEncoder<CreatorFeeConfigArgs> {
73
- return transformEncoder(
74
- getStructEncoder([
75
- ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
76
- ['version', getU8Encoder()],
77
- ['bump', getU8Encoder()],
78
- ['platformIndex', getU8Encoder()],
79
- ['platformId', fixEncoderSize(getBytesEncoder(), 44)],
80
- ['quoteMint', getAddressEncoder()],
81
- ['reserved', fixEncoderSize(getBytesEncoder(), 64)],
82
- ]),
83
- (value) => ({
84
- ...value,
85
- discriminator: CREATOR_FEE_CONFIG_DISCRIMINATOR,
86
- }),
87
- );
88
- }
89
-
90
- /** Gets the decoder for {@link CreatorFeeConfig} account data. */
91
- export function getCreatorFeeConfigDecoder(): FixedSizeDecoder<CreatorFeeConfig> {
92
- return getStructDecoder([
93
- ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
94
- ['version', getU8Decoder()],
95
- ['bump', getU8Decoder()],
96
- ['platformIndex', getU8Decoder()],
97
- ['platformId', fixDecoderSize(getBytesDecoder(), 44)],
98
- ['quoteMint', getAddressDecoder()],
99
- ['reserved', fixDecoderSize(getBytesDecoder(), 64)],
100
- ]);
101
- }
102
-
103
- /** Gets the codec for {@link CreatorFeeConfig} account data. */
104
- export function getCreatorFeeConfigCodec(): FixedSizeCodec<
105
- CreatorFeeConfigArgs,
106
- CreatorFeeConfig
107
- > {
108
- return combineCodec(
109
- getCreatorFeeConfigEncoder(),
110
- getCreatorFeeConfigDecoder(),
111
- );
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
- */
122
- export function decodeCreatorFeeConfig<TAddress extends string = string>(
123
- encodedAccount: EncodedAccount<TAddress>,
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
- */
133
- export function decodeCreatorFeeConfig<TAddress extends string = string>(
134
- encodedAccount: MaybeEncodedAccount<TAddress>,
135
- ): MaybeAccount<CreatorFeeConfig, TAddress>;
136
- export function decodeCreatorFeeConfig<TAddress extends string = string>(
137
- encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
138
- ):
139
- | Account<CreatorFeeConfig, TAddress>
140
- | MaybeAccount<CreatorFeeConfig, TAddress> {
141
- if (!('exists' in encodedAccount) || encodedAccount.exists) {
142
- if (encodedAccount.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) {
143
- const error = new Error(
144
- `decodeCreatorFeeConfig: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_NEXUS_PROGRAM_ADDRESS}`,
145
- );
146
- error.name = 'AccountOwnerMismatchError';
147
- throw error;
148
- }
149
- if (
150
- !containsBytes(
151
- encodedAccount.data,
152
- CREATOR_FEE_CONFIG_DISCRIMINATOR,
153
- 0,
154
- )
155
- ) {
156
- const error = new Error(
157
- `decodeCreatorFeeConfig: account ${encodedAccount.address} does not match the CreatorFeeConfig discriminator`,
158
- );
159
- error.name = 'AccountDiscriminatorMismatchError';
160
- throw error;
161
- }
162
- }
163
- return decodeAccount(
164
- encodedAccount as MaybeEncodedAccount<TAddress>,
165
- getCreatorFeeConfigDecoder(),
166
- );
167
- }
168
-
169
- /** Fetches a `CreatorFeeConfig` account, throwing when it does not exist or only holds lamports. */
170
- export async function fetchCreatorFeeConfig<TAddress extends string = string>(
171
- rpc: Parameters<typeof fetchEncodedAccount>[0],
172
- address: Address<TAddress>,
173
- config?: FetchAccountConfig,
174
- ): Promise<Account<CreatorFeeConfig, TAddress>> {
175
- const maybeAccount = await fetchMaybeCreatorFeeConfig(rpc, address, config);
176
- assertAccountExists(maybeAccount);
177
- return maybeAccount;
178
- }
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
- */
185
- export async function fetchMaybeCreatorFeeConfig<
186
- TAddress extends string = string,
187
- >(
188
- rpc: Parameters<typeof fetchEncodedAccount>[0],
189
- address: Address<TAddress>,
190
- config?: FetchAccountConfig,
191
- ): Promise<MaybeAccount<CreatorFeeConfig, TAddress>> {
192
- const maybeAccount = await fetchEncodedAccount(rpc, address, config);
193
- return decodeCreatorFeeConfig(
194
- accountIsCreated(maybeAccount)
195
- ? maybeAccount
196
- : { address, exists: false },
197
- );
198
- }
199
-
200
- /** Fetches `CreatorFeeConfig` accounts, throwing when any does not exist or only holds lamports. */
201
- export async function fetchAllCreatorFeeConfig(
202
- rpc: Parameters<typeof fetchEncodedAccounts>[0],
203
- addresses: Array<Address>,
204
- config?: FetchAccountsConfig,
205
- ): Promise<Account<CreatorFeeConfig>[]> {
206
- const maybeAccounts = await fetchAllMaybeCreatorFeeConfig(
207
- rpc,
208
- addresses,
209
- config,
210
- );
211
- assertAccountsExist(maybeAccounts);
212
- return maybeAccounts;
213
- }
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
- */
220
- export async function fetchAllMaybeCreatorFeeConfig(
221
- rpc: Parameters<typeof fetchEncodedAccounts>[0],
222
- addresses: Array<Address>,
223
- config?: FetchAccountsConfig,
224
- ): Promise<MaybeAccount<CreatorFeeConfig>[]> {
225
- const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
226
- return maybeAccounts.map((maybeAccount) =>
227
- decodeCreatorFeeConfig(
228
- accountIsCreated(maybeAccount)
229
- ? maybeAccount
230
- : { address: maybeAccount.address, exists: false },
231
- ),
232
- );
233
- }
234
-
235
- export function getCreatorFeeConfigSize(): number {
236
- return 151;
237
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * This code was AUTOGENERATED using the Codama library.
3
- * Please DO NOT EDIT THIS FILE, instead use visitors
4
- * to add features, then rerun Codama to update it.
5
- *
6
- * @see https://github.com/codama-idl/codama
7
- */
8
-
9
- import {
10
- combineCodec,
11
- getEnumDecoder,
12
- getEnumEncoder,
13
- type FixedSizeCodec,
14
- type FixedSizeDecoder,
15
- type FixedSizeEncoder,
16
- } from '@solana/kit';
17
-
18
- export enum CallerType {
19
- PlatformBondingCurve,
20
- PlatformPool,
21
- }
22
-
23
- export type CallerTypeArgs = CallerType;
24
-
25
- export function getCallerTypeEncoder(): FixedSizeEncoder<CallerTypeArgs> {
26
- return getEnumEncoder(CallerType);
27
- }
28
-
29
- export function getCallerTypeDecoder(): FixedSizeDecoder<CallerType> {
30
- return getEnumDecoder(CallerType);
31
- }
32
-
33
- export function getCallerTypeCodec(): FixedSizeCodec<
34
- CallerTypeArgs,
35
- CallerType
36
- > {
37
- return combineCodec(getCallerTypeEncoder(), getCallerTypeDecoder());
38
- }
@@ -1,60 +0,0 @@
1
- import { getAddressDecoder } from '@solana/kit';
2
- import type { Address, ReadonlyUint8Array } from '@solana/kit';
3
-
4
- const MAX_CREATOR_PLATFORM_LEN = 32;
5
-
6
- /** Returns the SHA-256 of `creatorPlatform` and `creatorId`, each prefixed with its byte length as a
7
- * little-endian u32. Throws `RangeError` if `creatorPlatform` is more than 32 bytes. */
8
- export async function creatorHashFromId(
9
- creatorPlatform: string,
10
- creatorId: string,
11
- ): Promise<Address> {
12
- const encoder = new TextEncoder();
13
- const platformBuf = encoder.encode(creatorPlatform);
14
- const idBuf = encoder.encode(creatorId);
15
-
16
- if (platformBuf.length > MAX_CREATOR_PLATFORM_LEN) {
17
- throw new RangeError(
18
- `creatorPlatform exceeds ${MAX_CREATOR_PLATFORM_LEN} bytes (got ${platformBuf.length})`,
19
- );
20
- }
21
- const platformLength = new Uint8Array(4);
22
- new DataView(platformLength.buffer).setUint32(0, platformBuf.length, true);
23
- const idLength = new Uint8Array(4);
24
- new DataView(idLength.buffer).setUint32(0, idBuf.length, true);
25
-
26
- const buf = new Uint8Array(4 + platformBuf.length + 4 + idBuf.length);
27
- buf.set(platformLength, 0);
28
- buf.set(platformBuf, 4);
29
- buf.set(idLength, 4 + platformBuf.length);
30
- buf.set(idBuf, 4 + platformBuf.length + 4);
31
-
32
- const hash = new Uint8Array(await crypto.subtle.digest('SHA-256', buf));
33
-
34
- const addressDecoder = getAddressDecoder();
35
- return addressDecoder.decode(hash);
36
- }
37
-
38
- /** Pads `text` with NUL bytes to `length` bytes, the form of `CreatorFeeConfig.platformId`.
39
- * Throws `RangeError` if `text` is longer. */
40
- export function encodeCreatorId(text: string, length: number): Uint8Array {
41
- const bytes = new TextEncoder().encode(text);
42
- if (bytes.length > length) {
43
- throw new RangeError(
44
- `text exceeds ${length} bytes (got ${bytes.length})`,
45
- );
46
- }
47
- const out = new Uint8Array(length);
48
- out.set(bytes, 0);
49
- return out;
50
- }
51
-
52
- /** Removes the trailing NUL bytes and decodes the rest as UTF-8. Pass the result, not the padded
53
- * bytes, to {@link creatorHashFromId}. */
54
- export function decodeCreatorId(bytes: ReadonlyUint8Array): string {
55
- let end = bytes.length;
56
- while (end > 0 && bytes[end - 1] === 0) {
57
- end -= 1;
58
- }
59
- return new TextDecoder().decode(bytes.slice(0, end));
60
- }