@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.
- package/README.md +8 -9
- package/dist/index.cjs +777 -433
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +678 -217
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +678 -217
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +777 -433
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/dex/generated/accounts/globalConfig.ts +39 -2
- package/src/dex/generated/accounts/pool.ts +60 -9
- package/src/dex/generated/accounts/rewardAccrual.ts +39 -2
- package/src/dex/generated/errors/sendDex.ts +16 -8
- package/src/dex/generated/events/creatorClaimEvent.ts +3 -2
- package/src/dex/generated/events/poolCreateEvent.ts +8 -2
- package/src/dex/generated/events/tokenCreateEvent.ts +8 -9
- package/src/dex/generated/events/tradeEvent.ts +9 -2
- package/src/dex/generated/index.ts +1 -0
- package/src/dex/generated/instructions/claimCreatorFees.ts +21 -5
- package/src/{nexus → dex}/generated/pdas/creatorFeeConfig.ts +6 -6
- package/src/dex/generated/pdas/index.ts +1 -0
- package/src/dex/generated/plugins/sendDex.ts +3 -0
- package/src/dex/generated/shared/index.ts +52 -0
- package/src/dex/trade.ts +12 -13
- package/src/launchpad/create.ts +13 -38
- package/src/launchpad/generated/accounts/bondingCurve.ts +62 -9
- package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
- package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
- package/src/launchpad/generated/errors/sendLaunchpad.ts +12 -4
- package/src/launchpad/generated/events/completeEvent.ts +3 -2
- package/src/launchpad/generated/events/creatorClaimEvent.ts +3 -2
- package/src/launchpad/generated/events/migrateEvent.ts +3 -2
- package/src/launchpad/generated/events/tokenCreateEvent.ts +10 -9
- package/src/launchpad/generated/events/tradeEvent.ts +9 -2
- package/src/launchpad/generated/index.ts +1 -0
- package/src/launchpad/generated/instructions/claimCreatorFees.ts +17 -4
- package/src/launchpad/generated/instructions/createToken.ts +32 -50
- package/src/launchpad/generated/instructions/migrate.ts +79 -12
- package/src/launchpad/generated/pdas/creatorFeeConfig.ts +39 -0
- package/src/launchpad/generated/pdas/index.ts +1 -0
- package/src/launchpad/generated/plugins/sendLaunchpad.ts +3 -0
- package/src/launchpad/generated/shared/index.ts +52 -0
- package/src/launchpad/migrate.ts +7 -4
- package/src/launchpad/trade.ts +15 -15
- package/src/math/amm.ts +40 -33
- package/src/math/fee-decay.ts +3 -2
- package/src/math/fees.ts +4 -2
- package/src/math/internal.ts +1 -1
- package/src/nexus/fee-helpers.ts +10 -5
- package/src/nexus/generated/accounts/altRegistry.ts +41 -2
- package/src/nexus/generated/accounts/feePreset.ts +43 -4
- package/src/nexus/generated/accounts/globalConfig.ts +39 -2
- package/src/nexus/generated/accounts/index.ts +0 -1
- package/src/nexus/generated/accounts/partnerConfig.ts +48 -5
- package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
- package/src/nexus/generated/accounts/rewardState.ts +41 -2
- package/src/nexus/generated/accounts/sendNexus.accounts.ts +0 -5
- package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
- package/src/nexus/generated/accounts/userRewardDebt.ts +42 -5
- package/src/nexus/generated/accounts/userStakePosition.ts +42 -5
- package/src/nexus/generated/errors/sendNexus.ts +12 -4
- package/src/nexus/generated/index.ts +1 -0
- package/src/nexus/generated/pdas/index.ts +0 -1
- package/src/nexus/generated/plugins/sendNexus.ts +0 -35
- package/src/nexus/generated/shared/index.ts +52 -0
- package/src/nexus/generated/types/dexFees.ts +4 -4
- package/src/nexus/generated/types/index.ts +0 -1
- package/src/nexus/generated/types/launchpadFees.ts +4 -4
- package/src/nexus/staking.ts +45 -41
- package/src/platform.ts +2 -2
- package/src/transfer-fee.ts +19 -17
- package/src/utils/chunk.ts +1 -1
- package/src/utils/index.ts +2 -5
- package/src/utils/mint-info.ts +8 -7
- package/src/utils/partner.ts +1 -1
- package/src/utils/pda.ts +1 -1
- package/src/nexus/generated/accounts/creatorFeeConfig.ts +0 -200
- package/src/nexus/generated/types/callerType.ts +0 -38
- package/src/utils/creator-hash.ts +0 -57
package/src/transfer-fee.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// Parses Token-2022 mint data by hand. The SDK does not depend on
|
|
2
|
+
// `@solana-program/token-2022`.
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
getAddressDecoder,
|
|
@@ -20,8 +20,8 @@ import { fetchInChunks } from './utils/chunk.js';
|
|
|
20
20
|
|
|
21
21
|
const MINT_BASE_LENGTH = 82;
|
|
22
22
|
|
|
23
|
-
// Token-2022 pads the base mint to the
|
|
24
|
-
//
|
|
23
|
+
// Token-2022 pads the base mint to 165 bytes, the token-account length. The
|
|
24
|
+
// account-type byte follows, then the TLV entries.
|
|
25
25
|
const ACCOUNT_TYPE_OFFSET = 165;
|
|
26
26
|
|
|
27
27
|
const ACCOUNT_TYPE_MINT = 1;
|
|
@@ -58,7 +58,7 @@ export interface TransferFeeEntry {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export interface TransferFeeConfig {
|
|
61
|
-
/** `undefined`
|
|
61
|
+
/** `undefined` if the config has no authority. Then the schedule cannot change. */
|
|
62
62
|
readonly authority: Address | undefined;
|
|
63
63
|
readonly older: TransferFeeEntry;
|
|
64
64
|
readonly newer: TransferFeeEntry;
|
|
@@ -80,13 +80,14 @@ function readEntry(view: DataView, start: number): TransferFeeEntry {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/** `
|
|
84
|
-
*
|
|
83
|
+
/** Decodes the `TransferFeeConfig` extension of a mint. `owner` is the program that owns the account.
|
|
84
|
+
* Returns `undefined` if the mint has no such extension. Throws `RangeError` if `owner` is not a
|
|
85
|
+
* token program or `data` is not a valid mint. */
|
|
85
86
|
export function decodeTransferFeeConfig(
|
|
86
87
|
data: Uint8Array,
|
|
87
88
|
owner: Address,
|
|
88
89
|
): TransferFeeConfig | undefined {
|
|
89
|
-
// Classic SPL
|
|
90
|
+
// Classic SPL mints have no extensions.
|
|
90
91
|
if (owner === TOKEN_PROGRAM_ADDRESS) return undefined;
|
|
91
92
|
if (owner !== TOKEN_2022_PROGRAM_ADDRESS) {
|
|
92
93
|
throw new RangeError(
|
|
@@ -94,14 +95,14 @@ export function decodeTransferFeeConfig(
|
|
|
94
95
|
);
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
// Token-2022
|
|
98
|
+
// A Token-2022 mint with no extensions is 82 bytes.
|
|
98
99
|
if (data.length === MINT_BASE_LENGTH) return undefined;
|
|
99
100
|
if (data.length < TLV_START) {
|
|
100
101
|
throw new RangeError(
|
|
101
102
|
`decodeTransferFeeConfig: a Token-2022 mint holds ${data.length} bytes, expected ${MINT_BASE_LENGTH} or at least ${TLV_START}`,
|
|
102
103
|
);
|
|
103
104
|
}
|
|
104
|
-
// Token accounts
|
|
105
|
+
// Token accounts use the same TLV layout.
|
|
105
106
|
if (data[ACCOUNT_TYPE_OFFSET] !== ACCOUNT_TYPE_MINT) {
|
|
106
107
|
throw new RangeError(
|
|
107
108
|
`decodeTransferFeeConfig: account type ${data[ACCOUNT_TYPE_OFFSET]} is not a mint`,
|
|
@@ -112,7 +113,7 @@ export function decodeTransferFeeConfig(
|
|
|
112
113
|
|
|
113
114
|
let offset = TLV_START;
|
|
114
115
|
while (offset < data.length) {
|
|
115
|
-
//
|
|
116
|
+
// SPL reads a tail too short for a type, or a zero type, as the end of the list.
|
|
116
117
|
if (offset + TLV_TYPE > data.length) return undefined;
|
|
117
118
|
const extensionType = view.getUint16(offset, true);
|
|
118
119
|
if (extensionType === UNINITIALIZED_TYPE) return undefined;
|
|
@@ -133,7 +134,7 @@ export function decodeTransferFeeConfig(
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
if (extensionType === TRANSFER_FEE_CONFIG_TYPE) {
|
|
136
|
-
//
|
|
137
|
+
// The extension is always 108 bytes.
|
|
137
138
|
if (length !== TRANSFER_FEE_CONFIG_LENGTH) {
|
|
138
139
|
throw new RangeError(
|
|
139
140
|
`decodeTransferFeeConfig: TransferFeeConfig holds ${length} bytes, expected ${TRANSFER_FEE_CONFIG_LENGTH}`,
|
|
@@ -152,7 +153,7 @@ export function decodeTransferFeeConfig(
|
|
|
152
153
|
return undefined;
|
|
153
154
|
}
|
|
154
155
|
|
|
155
|
-
/**
|
|
156
|
+
/** Returns the fee for `epoch`, as SPL `get_epoch_fee` does. The newer entry applies from its own epoch on. */
|
|
156
157
|
export function transferFeeAtEpoch(
|
|
157
158
|
config: TransferFeeConfig,
|
|
158
159
|
epoch: bigint,
|
|
@@ -170,8 +171,8 @@ export function mintFeeAtEpoch(
|
|
|
170
171
|
return config === undefined ? undefined : transferFeeAtEpoch(config, epoch);
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
// Omit the config,
|
|
174
|
-
//
|
|
174
|
+
// Omit the config, not `{ commitment: undefined }`. Kit deletes an undefined key, so the
|
|
175
|
+
// server default `finalized` applies. With no config, the client default applies.
|
|
175
176
|
function currentEpoch(
|
|
176
177
|
rpc: Rpc<GetEpochInfoApi>,
|
|
177
178
|
commitment: Commitment | undefined,
|
|
@@ -182,8 +183,9 @@ function currentEpoch(
|
|
|
182
183
|
.then((info) => info.epoch);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
/**
|
|
186
|
-
* the cluster
|
|
186
|
+
/** Reads the transfer fee of each mint for `epoch`. The result is valid only for that epoch.
|
|
187
|
+
* `epoch` defaults to the current cluster epoch, read with `getEpochInfo`. A mint without a
|
|
188
|
+
* transfer fee maps to `undefined`. Throws if a mint account is missing or does not decode. */
|
|
187
189
|
export async function fetchMintFees(
|
|
188
190
|
rpc: Rpc<GetMultipleAccountsApi & GetEpochInfoApi>,
|
|
189
191
|
mints: readonly Address[],
|
package/src/utils/chunk.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Address } from '@solana/kit';
|
|
|
3
3
|
/** RPCs reject a `getMultipleAccounts` call past this many addresses. */
|
|
4
4
|
const MAX_ACCOUNTS_PER_REQUEST = 100;
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/** Calls `read` once per 100 addresses. Results follow `addresses` order. */
|
|
7
7
|
export async function fetchInChunks<T>(
|
|
8
8
|
addresses: readonly Address[],
|
|
9
9
|
read: (chunk: Address[]) => Promise<readonly T[]>,
|
package/src/utils/index.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
decodeCreatorId,
|
|
4
|
-
encodeCreatorId,
|
|
5
|
-
} from './creator-hash.js';
|
|
1
|
+
// The three programs generate the same function.
|
|
2
|
+
export { accountIsCreated } from '../nexus/generated/shared/index.js';
|
|
6
3
|
export { fetchQuoteMintInfo, fetchQuoteMintInfos } from './mint-info.js';
|
|
7
4
|
export type { QuoteMintInfo } from './mint-info.js';
|
|
8
5
|
export type { PartnerInput } from './partner.js';
|
package/src/utils/mint-info.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
// transfer cannot reach.
|
|
1
|
+
// Reads the token program from the mint account. Do not hard-code it.
|
|
3
2
|
import {
|
|
4
3
|
getBase64Encoder,
|
|
5
4
|
type Address,
|
|
@@ -15,14 +14,14 @@ import {
|
|
|
15
14
|
} from '../constants.js';
|
|
16
15
|
import { fetchInChunks } from './chunk.js';
|
|
17
16
|
|
|
18
|
-
// Both token programs
|
|
17
|
+
// Both token programs use the same base mint: 36-byte `COption<Pubkey>` authority,
|
|
19
18
|
// u64 supply, then decimals.
|
|
20
19
|
const MINT_BASE_LENGTH = 82;
|
|
21
20
|
const MINT_DECIMALS_OFFSET = 44;
|
|
22
21
|
|
|
23
22
|
export interface QuoteMintInfo {
|
|
24
23
|
mint: Address;
|
|
25
|
-
/**
|
|
24
|
+
/** Cannot change after the mint is created. */
|
|
26
25
|
decimals: number;
|
|
27
26
|
/** The account's owner: `TOKEN_PROGRAM_ADDRESS` or `TOKEN_2022_PROGRAM_ADDRESS`. */
|
|
28
27
|
tokenProgram: Address;
|
|
@@ -41,7 +40,7 @@ function decodeMintInfo(
|
|
|
41
40
|
`fetchQuoteMintInfo: ${mint} is owned by ${owner}, which is not a token program`,
|
|
42
41
|
);
|
|
43
42
|
}
|
|
44
|
-
// A
|
|
43
|
+
// A minimum: Token-2022 mints with extensions are longer.
|
|
45
44
|
if (data.length < MINT_BASE_LENGTH) {
|
|
46
45
|
throw new Error(
|
|
47
46
|
`fetchQuoteMintInfo: ${mint} holds ${data.length} bytes, too short for a mint`,
|
|
@@ -50,7 +49,8 @@ function decodeMintInfo(
|
|
|
50
49
|
return { mint, decimals: data[MINT_DECIMALS_OFFSET], tokenProgram: owner };
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
/**
|
|
52
|
+
/** Reads the decimals and token program of `mint`. Throws if the account does not exist, a token
|
|
53
|
+
* program does not own it, or it is too short for a mint. */
|
|
54
54
|
export async function fetchQuoteMintInfo(
|
|
55
55
|
rpc: Rpc<GetAccountInfoApi>,
|
|
56
56
|
mint: Address,
|
|
@@ -71,7 +71,8 @@ export async function fetchQuoteMintInfo(
|
|
|
71
71
|
return decodeMintInfo(mint, data, value.owner);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
/**
|
|
74
|
+
/** Reads the decimals and token program of each mint. Results follow `mints` order. Throws as
|
|
75
|
+
* {@link fetchQuoteMintInfo} does. */
|
|
75
76
|
export async function fetchQuoteMintInfos(
|
|
76
77
|
rpc: Rpc<GetMultipleAccountsApi>,
|
|
77
78
|
mints: readonly Address[],
|
package/src/utils/partner.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransactionSigner } from '@solana/kit';
|
|
2
2
|
import type { DEFAULT_PARTNER } from '../constants.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** A partner signer, or `DEFAULT_PARTNER` as a bare address. Any other partner must sign. */
|
|
5
5
|
export type PartnerInput = TransactionSigner | typeof DEFAULT_PARTNER;
|
package/src/utils/pda.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const addressEncoder = getAddressEncoder();
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/** Derives the associated token account of `wallet` for `mint` under `tokenProgram`. */
|
|
11
11
|
export async function findAssociatedTokenPda(
|
|
12
12
|
wallet: Address,
|
|
13
13
|
mint: Address,
|
|
@@ -1,200 +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
|
-
|
|
42
|
-
export const CREATOR_FEE_CONFIG_DISCRIMINATOR: ReadonlyUint8Array =
|
|
43
|
-
new Uint8Array([160, 88, 34, 74, 215, 196, 130, 32]);
|
|
44
|
-
|
|
45
|
-
export function getCreatorFeeConfigDiscriminatorBytes(): ReadonlyUint8Array {
|
|
46
|
-
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
47
|
-
CREATOR_FEE_CONFIG_DISCRIMINATOR,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type CreatorFeeConfig = {
|
|
52
|
-
discriminator: ReadonlyUint8Array;
|
|
53
|
-
version: number;
|
|
54
|
-
bump: number;
|
|
55
|
-
platformIndex: number;
|
|
56
|
-
platformId: ReadonlyUint8Array;
|
|
57
|
-
quoteMint: Address;
|
|
58
|
-
reserved: ReadonlyUint8Array;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export type CreatorFeeConfigArgs = {
|
|
62
|
-
version: number;
|
|
63
|
-
bump: number;
|
|
64
|
-
platformIndex: number;
|
|
65
|
-
platformId: ReadonlyUint8Array;
|
|
66
|
-
quoteMint: Address;
|
|
67
|
-
reserved: ReadonlyUint8Array;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/** Gets the encoder for {@link CreatorFeeConfigArgs} account data. */
|
|
71
|
-
export function getCreatorFeeConfigEncoder(): FixedSizeEncoder<CreatorFeeConfigArgs> {
|
|
72
|
-
return transformEncoder(
|
|
73
|
-
getStructEncoder([
|
|
74
|
-
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
75
|
-
['version', getU8Encoder()],
|
|
76
|
-
['bump', getU8Encoder()],
|
|
77
|
-
['platformIndex', getU8Encoder()],
|
|
78
|
-
['platformId', fixEncoderSize(getBytesEncoder(), 44)],
|
|
79
|
-
['quoteMint', getAddressEncoder()],
|
|
80
|
-
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
|
|
81
|
-
]),
|
|
82
|
-
(value) => ({
|
|
83
|
-
...value,
|
|
84
|
-
discriminator: CREATOR_FEE_CONFIG_DISCRIMINATOR,
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Gets the decoder for {@link CreatorFeeConfig} account data. */
|
|
90
|
-
export function getCreatorFeeConfigDecoder(): FixedSizeDecoder<CreatorFeeConfig> {
|
|
91
|
-
return getStructDecoder([
|
|
92
|
-
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
93
|
-
['version', getU8Decoder()],
|
|
94
|
-
['bump', getU8Decoder()],
|
|
95
|
-
['platformIndex', getU8Decoder()],
|
|
96
|
-
['platformId', fixDecoderSize(getBytesDecoder(), 44)],
|
|
97
|
-
['quoteMint', getAddressDecoder()],
|
|
98
|
-
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
|
|
99
|
-
]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Gets the codec for {@link CreatorFeeConfig} account data. */
|
|
103
|
-
export function getCreatorFeeConfigCodec(): FixedSizeCodec<
|
|
104
|
-
CreatorFeeConfigArgs,
|
|
105
|
-
CreatorFeeConfig
|
|
106
|
-
> {
|
|
107
|
-
return combineCodec(
|
|
108
|
-
getCreatorFeeConfigEncoder(),
|
|
109
|
-
getCreatorFeeConfigDecoder(),
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function decodeCreatorFeeConfig<TAddress extends string = string>(
|
|
114
|
-
encodedAccount: EncodedAccount<TAddress>,
|
|
115
|
-
): Account<CreatorFeeConfig, TAddress>;
|
|
116
|
-
export function decodeCreatorFeeConfig<TAddress extends string = string>(
|
|
117
|
-
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
118
|
-
): MaybeAccount<CreatorFeeConfig, TAddress>;
|
|
119
|
-
export function decodeCreatorFeeConfig<TAddress extends string = string>(
|
|
120
|
-
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
121
|
-
):
|
|
122
|
-
| Account<CreatorFeeConfig, TAddress>
|
|
123
|
-
| MaybeAccount<CreatorFeeConfig, TAddress> {
|
|
124
|
-
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
125
|
-
if (encodedAccount.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) {
|
|
126
|
-
const error = new Error(
|
|
127
|
-
`decodeCreatorFeeConfig: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_NEXUS_PROGRAM_ADDRESS}`,
|
|
128
|
-
);
|
|
129
|
-
error.name = 'AccountOwnerMismatchError';
|
|
130
|
-
throw error;
|
|
131
|
-
}
|
|
132
|
-
if (
|
|
133
|
-
!containsBytes(
|
|
134
|
-
encodedAccount.data,
|
|
135
|
-
CREATOR_FEE_CONFIG_DISCRIMINATOR,
|
|
136
|
-
0,
|
|
137
|
-
)
|
|
138
|
-
) {
|
|
139
|
-
const error = new Error(
|
|
140
|
-
`decodeCreatorFeeConfig: account ${encodedAccount.address} does not match the CreatorFeeConfig discriminator`,
|
|
141
|
-
);
|
|
142
|
-
error.name = 'AccountDiscriminatorMismatchError';
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return decodeAccount(
|
|
147
|
-
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
148
|
-
getCreatorFeeConfigDecoder(),
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export async function fetchCreatorFeeConfig<TAddress extends string = string>(
|
|
153
|
-
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
154
|
-
address: Address<TAddress>,
|
|
155
|
-
config?: FetchAccountConfig,
|
|
156
|
-
): Promise<Account<CreatorFeeConfig, TAddress>> {
|
|
157
|
-
const maybeAccount = await fetchMaybeCreatorFeeConfig(rpc, address, config);
|
|
158
|
-
assertAccountExists(maybeAccount);
|
|
159
|
-
return maybeAccount;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export async function fetchMaybeCreatorFeeConfig<
|
|
163
|
-
TAddress extends string = string,
|
|
164
|
-
>(
|
|
165
|
-
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
166
|
-
address: Address<TAddress>,
|
|
167
|
-
config?: FetchAccountConfig,
|
|
168
|
-
): Promise<MaybeAccount<CreatorFeeConfig, TAddress>> {
|
|
169
|
-
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
170
|
-
return decodeCreatorFeeConfig(maybeAccount);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export async function fetchAllCreatorFeeConfig(
|
|
174
|
-
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
175
|
-
addresses: Array<Address>,
|
|
176
|
-
config?: FetchAccountsConfig,
|
|
177
|
-
): Promise<Account<CreatorFeeConfig>[]> {
|
|
178
|
-
const maybeAccounts = await fetchAllMaybeCreatorFeeConfig(
|
|
179
|
-
rpc,
|
|
180
|
-
addresses,
|
|
181
|
-
config,
|
|
182
|
-
);
|
|
183
|
-
assertAccountsExist(maybeAccounts);
|
|
184
|
-
return maybeAccounts;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export async function fetchAllMaybeCreatorFeeConfig(
|
|
188
|
-
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
189
|
-
addresses: Array<Address>,
|
|
190
|
-
config?: FetchAccountsConfig,
|
|
191
|
-
): Promise<MaybeAccount<CreatorFeeConfig>[]> {
|
|
192
|
-
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
193
|
-
return maybeAccounts.map((maybeAccount) =>
|
|
194
|
-
decodeCreatorFeeConfig(maybeAccount),
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function getCreatorFeeConfigSize(): number {
|
|
199
|
-
return 151;
|
|
200
|
-
}
|
|
@@ -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,57 +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
|
-
/** SHA-256 of the LE-u32-length-prefixed platform and id. Frozen: it seeds live PDAs. */
|
|
7
|
-
export async function creatorHashFromId(
|
|
8
|
-
creatorPlatform: string,
|
|
9
|
-
creatorId: string,
|
|
10
|
-
): Promise<Address> {
|
|
11
|
-
const encoder = new TextEncoder();
|
|
12
|
-
const platformBuf = encoder.encode(creatorPlatform);
|
|
13
|
-
const idBuf = encoder.encode(creatorId);
|
|
14
|
-
|
|
15
|
-
if (platformBuf.length > MAX_CREATOR_PLATFORM_LEN) {
|
|
16
|
-
throw new RangeError(
|
|
17
|
-
`creatorPlatform exceeds ${MAX_CREATOR_PLATFORM_LEN} bytes (got ${platformBuf.length})`,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
const platformLength = new Uint8Array(4);
|
|
21
|
-
new DataView(platformLength.buffer).setUint32(0, platformBuf.length, true);
|
|
22
|
-
const idLength = new Uint8Array(4);
|
|
23
|
-
new DataView(idLength.buffer).setUint32(0, idBuf.length, true);
|
|
24
|
-
|
|
25
|
-
const buf = new Uint8Array(4 + platformBuf.length + 4 + idBuf.length);
|
|
26
|
-
buf.set(platformLength, 0);
|
|
27
|
-
buf.set(platformBuf, 4);
|
|
28
|
-
buf.set(idLength, 4 + platformBuf.length);
|
|
29
|
-
buf.set(idBuf, 4 + platformBuf.length + 4);
|
|
30
|
-
|
|
31
|
-
const hash = new Uint8Array(await crypto.subtle.digest('SHA-256', buf));
|
|
32
|
-
|
|
33
|
-
const addressDecoder = getAddressDecoder();
|
|
34
|
-
return addressDecoder.decode(hash);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** NUL-pads `text` to `length` bytes, the on-chain `CreatorFeeConfig.platformId` form; throws RangeError if longer. */
|
|
38
|
-
export function encodeCreatorId(text: string, length: number): Uint8Array {
|
|
39
|
-
const bytes = new TextEncoder().encode(text);
|
|
40
|
-
if (bytes.length > length) {
|
|
41
|
-
throw new RangeError(
|
|
42
|
-
`text exceeds ${length} bytes (got ${bytes.length})`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
const out = new Uint8Array(length);
|
|
46
|
-
out.set(bytes, 0);
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Strips NUL padding. Pass this, never the padded array, to {@link creatorHashFromId}: the hash is length-prefixed. */
|
|
51
|
-
export function decodeCreatorId(bytes: ReadonlyUint8Array): string {
|
|
52
|
-
let end = bytes.length;
|
|
53
|
-
while (end > 0 && bytes[end - 1] === 0) {
|
|
54
|
-
end -= 1;
|
|
55
|
-
}
|
|
56
|
-
return new TextDecoder().decode(bytes.slice(0, end));
|
|
57
|
-
}
|