@send-fun/sdk 1.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.cjs +12808 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4406 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4405 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +12749 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +72 -0
- package/src/constants.ts +38 -0
- package/src/dex/generated/accounts/globalConfig.ts +189 -0
- package/src/dex/generated/accounts/index.ts +12 -0
- package/src/dex/generated/accounts/pool.ts +244 -0
- package/src/dex/generated/accounts/rewardAccrual.ts +191 -0
- package/src/dex/generated/accounts/sendDex.accounts.ts +47 -0
- package/src/dex/generated/errors/index.ts +9 -0
- package/src/dex/generated/errors/sendDex.ts +161 -0
- package/src/dex/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/dex/generated/events/creatorClaimEvent.ts +119 -0
- package/src/dex/generated/events/depositQuoteEvent.ts +115 -0
- package/src/dex/generated/events/index.ts +16 -0
- package/src/dex/generated/events/poolCreateEvent.ts +128 -0
- package/src/dex/generated/events/protocolClaimEvent.ts +111 -0
- package/src/dex/generated/events/sendDex.events.ts +184 -0
- package/src/dex/generated/events/tokenCreateEvent.ts +143 -0
- package/src/dex/generated/events/tradeEvent.ts +143 -0
- package/src/dex/generated/index.ts +16 -0
- package/src/dex/generated/instructions/buyExactIn.ts +815 -0
- package/src/dex/generated/instructions/buyExactOut.ts +815 -0
- package/src/dex/generated/instructions/claimCreatorFees.ts +648 -0
- package/src/dex/generated/instructions/claimProtocolFees.ts +640 -0
- package/src/dex/generated/instructions/index.ts +15 -0
- package/src/dex/generated/instructions/sellExactIn.ts +815 -0
- package/src/dex/generated/instructions/sellExactOut.ts +815 -0
- package/src/dex/generated/instructions/sendDex.instructions.ts +173 -0
- package/src/dex/generated/pdas/eventAuthority.ts +20 -0
- package/src/dex/generated/pdas/globalConfig.ts +20 -0
- package/src/dex/generated/pdas/index.ts +14 -0
- package/src/dex/generated/pdas/lpMint.ts +36 -0
- package/src/dex/generated/pdas/pool.ts +34 -0
- package/src/dex/generated/pdas/rewardAccrual.ts +37 -0
- package/src/dex/generated/pdas/wsolRewardAccrual.ts +20 -0
- package/src/dex/generated/plugins/index.ts +9 -0
- package/src/dex/generated/plugins/sendDex.ts +282 -0
- package/src/dex/generated/programs/index.ts +9 -0
- package/src/dex/generated/programs/sendDex.ts +12 -0
- package/src/dex/generated/types/index.ts +10 -0
- package/src/dex/generated/types/poolStatus.ts +38 -0
- package/src/dex/generated/types/tradeDirection.ts +38 -0
- package/src/dex/index.ts +8 -0
- package/src/dex/trade.ts +215 -0
- package/src/index.ts +8 -0
- package/src/launchpad/create.ts +116 -0
- package/src/launchpad/generated/accounts/bondingCurve.ts +273 -0
- package/src/launchpad/generated/accounts/globalConfig.ts +211 -0
- package/src/launchpad/generated/accounts/index.ts +12 -0
- package/src/launchpad/generated/accounts/rewardAccrual.ts +191 -0
- package/src/launchpad/generated/accounts/sendLaunchpad.accounts.ts +50 -0
- package/src/launchpad/generated/errors/index.ts +9 -0
- package/src/launchpad/generated/errors/sendLaunchpad.ts +175 -0
- package/src/launchpad/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/launchpad/generated/events/completeEvent.ts +120 -0
- package/src/launchpad/generated/events/creatorClaimEvent.ts +122 -0
- package/src/launchpad/generated/events/index.ts +17 -0
- package/src/launchpad/generated/events/migrateEvent.ts +121 -0
- package/src/launchpad/generated/events/protocolClaimEvent.ts +114 -0
- package/src/launchpad/generated/events/recycleEvent.ts +113 -0
- package/src/launchpad/generated/events/sendLaunchpad.events.ts +207 -0
- package/src/launchpad/generated/events/tokenCreateEvent.ts +156 -0
- package/src/launchpad/generated/events/tradeEvent.ts +148 -0
- package/src/launchpad/generated/index.ts +16 -0
- package/src/launchpad/generated/instructions/buyExactIn.ts +818 -0
- package/src/launchpad/generated/instructions/buyExactOut.ts +818 -0
- package/src/launchpad/generated/instructions/claimCreatorFees.ts +651 -0
- package/src/launchpad/generated/instructions/claimProtocolFees.ts +640 -0
- package/src/launchpad/generated/instructions/createToken.ts +1150 -0
- package/src/launchpad/generated/instructions/index.ts +17 -0
- package/src/launchpad/generated/instructions/migrate.ts +840 -0
- package/src/launchpad/generated/instructions/sellExactIn.ts +818 -0
- package/src/launchpad/generated/instructions/sellExactOut.ts +818 -0
- package/src/launchpad/generated/instructions/sendLaunchpad.instructions.ts +210 -0
- package/src/launchpad/generated/pdas/bondingCurve.ts +39 -0
- package/src/launchpad/generated/pdas/eventAuthority.ts +20 -0
- package/src/launchpad/generated/pdas/globalConfig.ts +20 -0
- package/src/launchpad/generated/pdas/index.ts +14 -0
- package/src/launchpad/generated/pdas/migrationAuthority.ts +20 -0
- package/src/launchpad/generated/pdas/rewardAccrual.ts +37 -0
- package/src/launchpad/generated/pdas/wsolRewardAccrual.ts +20 -0
- package/src/launchpad/generated/plugins/index.ts +9 -0
- package/src/launchpad/generated/plugins/sendLaunchpad.ts +315 -0
- package/src/launchpad/generated/programs/index.ts +9 -0
- package/src/launchpad/generated/programs/sendLaunchpad.ts +12 -0
- package/src/launchpad/generated/types/bondingCurveStatus.ts +43 -0
- package/src/launchpad/generated/types/index.ts +10 -0
- package/src/launchpad/generated/types/tradeDirection.ts +38 -0
- package/src/launchpad/index.ts +10 -0
- package/src/launchpad/migrate.ts +54 -0
- package/src/launchpad/trade.ts +247 -0
- package/src/math/amm.ts +511 -0
- package/src/math/fee-decay.ts +49 -0
- package/src/math/fees.ts +75 -0
- package/src/math/index.ts +3 -0
- package/src/math/internal.ts +16 -0
- package/src/nexus/fee-helpers.ts +49 -0
- package/src/nexus/generated/accounts/altRegistry.ts +177 -0
- package/src/nexus/generated/accounts/creatorFeeConfig.ts +200 -0
- package/src/nexus/generated/accounts/feePreset.ts +196 -0
- package/src/nexus/generated/accounts/globalConfig.ts +188 -0
- package/src/nexus/generated/accounts/index.ts +19 -0
- package/src/nexus/generated/accounts/partnerConfig.ts +209 -0
- package/src/nexus/generated/accounts/partnerMetadata.ts +216 -0
- package/src/nexus/generated/accounts/rewardState.ts +209 -0
- package/src/nexus/generated/accounts/sendNexus.accounts.ts +85 -0
- package/src/nexus/generated/accounts/stakingConfig.ts +197 -0
- package/src/nexus/generated/accounts/userRewardDebt.ts +221 -0
- package/src/nexus/generated/accounts/userStakePosition.ts +218 -0
- package/src/nexus/generated/constants/index.ts +9 -0
- package/src/nexus/generated/constants/sendNexus.ts +13 -0
- package/src/nexus/generated/errors/index.ts +9 -0
- package/src/nexus/generated/errors/sendNexus.ts +229 -0
- package/src/nexus/generated/events/anchorEventCpiDiscriminator.framing.ts +28 -0
- package/src/nexus/generated/events/claimEvent.ts +106 -0
- package/src/nexus/generated/events/index.ts +13 -0
- package/src/nexus/generated/events/sendNexus.events.ts +121 -0
- package/src/nexus/generated/events/stakeEvent.ts +106 -0
- package/src/nexus/generated/events/unstakeEvent.ts +106 -0
- package/src/nexus/generated/index.ts +17 -0
- package/src/nexus/generated/instructions/claim.ts +740 -0
- package/src/nexus/generated/instructions/createUserRewardDebt.ts +498 -0
- package/src/nexus/generated/instructions/index.ts +14 -0
- package/src/nexus/generated/instructions/sendNexus.instructions.ts +146 -0
- package/src/nexus/generated/instructions/settle.ts +517 -0
- package/src/nexus/generated/instructions/stake.ts +615 -0
- package/src/nexus/generated/instructions/unstake.ts +593 -0
- package/src/nexus/generated/pdas/altRegistry.ts +20 -0
- package/src/nexus/generated/pdas/creatorFeeConfig.ts +39 -0
- package/src/nexus/generated/pdas/defaultFeePreset.ts +37 -0
- package/src/nexus/generated/pdas/defaultPartner.ts +40 -0
- package/src/nexus/generated/pdas/defaultPartnerMetadata.ts +42 -0
- package/src/nexus/generated/pdas/eventAuthority.ts +20 -0
- package/src/nexus/generated/pdas/feePreset.ts +39 -0
- package/src/nexus/generated/pdas/globalConfig.ts +20 -0
- package/src/nexus/generated/pdas/index.ts +22 -0
- package/src/nexus/generated/pdas/partnerConfig.ts +36 -0
- package/src/nexus/generated/pdas/partnerMetadata.ts +38 -0
- package/src/nexus/generated/pdas/rewardState.ts +36 -0
- package/src/nexus/generated/pdas/stakingConfig.ts +20 -0
- package/src/nexus/generated/pdas/userRewardDebt.ts +41 -0
- package/src/nexus/generated/pdas/userStakePosition.ts +39 -0
- package/src/nexus/generated/plugins/index.ts +9 -0
- package/src/nexus/generated/plugins/sendNexus.ts +494 -0
- package/src/nexus/generated/programs/index.ts +9 -0
- package/src/nexus/generated/programs/sendNexus.ts +12 -0
- package/src/nexus/generated/types/authPlatformEntry.ts +52 -0
- package/src/nexus/generated/types/callerType.ts +38 -0
- package/src/nexus/generated/types/dexFees.ts +64 -0
- package/src/nexus/generated/types/feeConfig.ts +73 -0
- package/src/nexus/generated/types/index.ts +13 -0
- package/src/nexus/generated/types/launchpadFees.ts +63 -0
- package/src/nexus/index.ts +9 -0
- package/src/nexus/staking.ts +581 -0
- package/src/platform.ts +19 -0
- package/src/transfer-fee.ts +216 -0
- package/src/utils/chunk.ts +21 -0
- package/src/utils/creator-hash.ts +57 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/mint-info.ts +102 -0
- package/src/utils/partner.ts +5 -0
- package/src/utils/pda.ts +24 -0
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
getU128Decoder,
|
|
26
|
+
getU128Encoder,
|
|
27
|
+
getU64Decoder,
|
|
28
|
+
getU64Encoder,
|
|
29
|
+
getU8Decoder,
|
|
30
|
+
getU8Encoder,
|
|
31
|
+
transformEncoder,
|
|
32
|
+
type Account,
|
|
33
|
+
type Address,
|
|
34
|
+
type EncodedAccount,
|
|
35
|
+
type FetchAccountConfig,
|
|
36
|
+
type FetchAccountsConfig,
|
|
37
|
+
type FixedSizeCodec,
|
|
38
|
+
type FixedSizeDecoder,
|
|
39
|
+
type FixedSizeEncoder,
|
|
40
|
+
type MaybeAccount,
|
|
41
|
+
type MaybeEncodedAccount,
|
|
42
|
+
type ReadonlyUint8Array,
|
|
43
|
+
} from '@solana/kit';
|
|
44
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
45
|
+
|
|
46
|
+
export const REWARD_ACCRUAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
47
|
+
158, 244, 116, 30, 227, 132, 105, 182,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
export function getRewardAccrualDiscriminatorBytes(): ReadonlyUint8Array {
|
|
51
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
52
|
+
REWARD_ACCRUAL_DISCRIMINATOR,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type RewardAccrual = {
|
|
57
|
+
discriminator: ReadonlyUint8Array;
|
|
58
|
+
version: number;
|
|
59
|
+
bump: number;
|
|
60
|
+
quoteMint: Address;
|
|
61
|
+
accPerToken: bigint;
|
|
62
|
+
totalDeposited: bigint;
|
|
63
|
+
reserved: ReadonlyUint8Array;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type RewardAccrualArgs = {
|
|
67
|
+
version: number;
|
|
68
|
+
bump: number;
|
|
69
|
+
quoteMint: Address;
|
|
70
|
+
accPerToken: number | bigint;
|
|
71
|
+
totalDeposited: number | bigint;
|
|
72
|
+
reserved: ReadonlyUint8Array;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Gets the encoder for {@link RewardAccrualArgs} account data. */
|
|
76
|
+
export function getRewardAccrualEncoder(): FixedSizeEncoder<RewardAccrualArgs> {
|
|
77
|
+
return transformEncoder(
|
|
78
|
+
getStructEncoder([
|
|
79
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
80
|
+
['version', getU8Encoder()],
|
|
81
|
+
['bump', getU8Encoder()],
|
|
82
|
+
['quoteMint', getAddressEncoder()],
|
|
83
|
+
['accPerToken', getU128Encoder()],
|
|
84
|
+
['totalDeposited', getU64Encoder()],
|
|
85
|
+
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
|
|
86
|
+
]),
|
|
87
|
+
(value) => ({ ...value, discriminator: REWARD_ACCRUAL_DISCRIMINATOR }),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Gets the decoder for {@link RewardAccrual} account data. */
|
|
92
|
+
export function getRewardAccrualDecoder(): FixedSizeDecoder<RewardAccrual> {
|
|
93
|
+
return getStructDecoder([
|
|
94
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
95
|
+
['version', getU8Decoder()],
|
|
96
|
+
['bump', getU8Decoder()],
|
|
97
|
+
['quoteMint', getAddressDecoder()],
|
|
98
|
+
['accPerToken', getU128Decoder()],
|
|
99
|
+
['totalDeposited', getU64Decoder()],
|
|
100
|
+
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Gets the codec for {@link RewardAccrual} account data. */
|
|
105
|
+
export function getRewardAccrualCodec(): FixedSizeCodec<
|
|
106
|
+
RewardAccrualArgs,
|
|
107
|
+
RewardAccrual
|
|
108
|
+
> {
|
|
109
|
+
return combineCodec(getRewardAccrualEncoder(), getRewardAccrualDecoder());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function decodeRewardAccrual<TAddress extends string = string>(
|
|
113
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
114
|
+
): Account<RewardAccrual, TAddress>;
|
|
115
|
+
export function decodeRewardAccrual<TAddress extends string = string>(
|
|
116
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
117
|
+
): MaybeAccount<RewardAccrual, TAddress>;
|
|
118
|
+
export function decodeRewardAccrual<TAddress extends string = string>(
|
|
119
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
120
|
+
): Account<RewardAccrual, TAddress> | MaybeAccount<RewardAccrual, TAddress> {
|
|
121
|
+
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
122
|
+
if (encodedAccount.programAddress !== SEND_DEX_PROGRAM_ADDRESS) {
|
|
123
|
+
const error = new Error(
|
|
124
|
+
`decodeRewardAccrual: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_DEX_PROGRAM_ADDRESS}`,
|
|
125
|
+
);
|
|
126
|
+
error.name = 'AccountOwnerMismatchError';
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
if (
|
|
130
|
+
!containsBytes(encodedAccount.data, REWARD_ACCRUAL_DISCRIMINATOR, 0)
|
|
131
|
+
) {
|
|
132
|
+
const error = new Error(
|
|
133
|
+
`decodeRewardAccrual: account ${encodedAccount.address} does not match the RewardAccrual discriminator`,
|
|
134
|
+
);
|
|
135
|
+
error.name = 'AccountDiscriminatorMismatchError';
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return decodeAccount(
|
|
140
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
141
|
+
getRewardAccrualDecoder(),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function fetchRewardAccrual<TAddress extends string = string>(
|
|
146
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
147
|
+
address: Address<TAddress>,
|
|
148
|
+
config?: FetchAccountConfig,
|
|
149
|
+
): Promise<Account<RewardAccrual, TAddress>> {
|
|
150
|
+
const maybeAccount = await fetchMaybeRewardAccrual(rpc, address, config);
|
|
151
|
+
assertAccountExists(maybeAccount);
|
|
152
|
+
return maybeAccount;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function fetchMaybeRewardAccrual<TAddress extends string = string>(
|
|
156
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
157
|
+
address: Address<TAddress>,
|
|
158
|
+
config?: FetchAccountConfig,
|
|
159
|
+
): Promise<MaybeAccount<RewardAccrual, TAddress>> {
|
|
160
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
161
|
+
return decodeRewardAccrual(maybeAccount);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function fetchAllRewardAccrual(
|
|
165
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
166
|
+
addresses: Array<Address>,
|
|
167
|
+
config?: FetchAccountsConfig,
|
|
168
|
+
): Promise<Account<RewardAccrual>[]> {
|
|
169
|
+
const maybeAccounts = await fetchAllMaybeRewardAccrual(
|
|
170
|
+
rpc,
|
|
171
|
+
addresses,
|
|
172
|
+
config,
|
|
173
|
+
);
|
|
174
|
+
assertAccountsExist(maybeAccounts);
|
|
175
|
+
return maybeAccounts;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export async function fetchAllMaybeRewardAccrual(
|
|
179
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
180
|
+
addresses: Array<Address>,
|
|
181
|
+
config?: FetchAccountsConfig,
|
|
182
|
+
): Promise<MaybeAccount<RewardAccrual>[]> {
|
|
183
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
184
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
185
|
+
decodeRewardAccrual(maybeAccount),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function getRewardAccrualSize(): number {
|
|
190
|
+
return 130;
|
|
191
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
type Address,
|
|
12
|
+
type ReadonlyUint8Array,
|
|
13
|
+
} from '@solana/kit';
|
|
14
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
15
|
+
import { GLOBAL_CONFIG_DISCRIMINATOR } from './globalConfig.js';
|
|
16
|
+
import { POOL_DISCRIMINATOR } from './pool.js';
|
|
17
|
+
import { REWARD_ACCRUAL_DISCRIMINATOR } from './rewardAccrual.js';
|
|
18
|
+
|
|
19
|
+
/** Account kinds of the sendDex program. */
|
|
20
|
+
export type SendDexAccountType = 'globalConfig' | 'pool' | 'rewardAccrual';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Identifies sendDex account data by its discriminators.
|
|
24
|
+
* Returns `null` when the account belongs to another program or the data matches no known account.
|
|
25
|
+
*/
|
|
26
|
+
export function identifySendDexAccount(
|
|
27
|
+
account:
|
|
28
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
29
|
+
| ReadonlyUint8Array,
|
|
30
|
+
): SendDexAccountType | null {
|
|
31
|
+
if (
|
|
32
|
+
'data' in account &&
|
|
33
|
+
account.programAddress !== SEND_DEX_PROGRAM_ADDRESS
|
|
34
|
+
)
|
|
35
|
+
return null;
|
|
36
|
+
const data = 'data' in account ? account.data : account;
|
|
37
|
+
if (containsBytes(data, GLOBAL_CONFIG_DISCRIMINATOR, 0)) {
|
|
38
|
+
return 'globalConfig';
|
|
39
|
+
}
|
|
40
|
+
if (containsBytes(data, POOL_DISCRIMINATOR, 0)) {
|
|
41
|
+
return 'pool';
|
|
42
|
+
}
|
|
43
|
+
if (containsBytes(data, REWARD_ACCRUAL_DISCRIMINATOR, 0)) {
|
|
44
|
+
return 'rewardAccrual';
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
isProgramError,
|
|
11
|
+
type Address,
|
|
12
|
+
type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
|
|
13
|
+
type SolanaError,
|
|
14
|
+
} from '@solana/kit';
|
|
15
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
16
|
+
|
|
17
|
+
/** PoolPaused: Pool is paused */
|
|
18
|
+
export const SEND_DEX_ERROR__POOL_PAUSED = 0x1770; // 6000
|
|
19
|
+
/** SlippageExceeded: Slippage tolerance exceeded */
|
|
20
|
+
export const SEND_DEX_ERROR__SLIPPAGE_EXCEEDED = 0x1771; // 6001
|
|
21
|
+
/** InsufficientBalance: Insufficient balance in source account */
|
|
22
|
+
export const SEND_DEX_ERROR__INSUFFICIENT_BALANCE = 0x1772; // 6002
|
|
23
|
+
/** InvalidBaseMint: Invalid base mint */
|
|
24
|
+
export const SEND_DEX_ERROR__INVALID_BASE_MINT = 0x1773; // 6003
|
|
25
|
+
/** InvalidQuoteMint: Invalid quote mint */
|
|
26
|
+
export const SEND_DEX_ERROR__INVALID_QUOTE_MINT = 0x1774; // 6004
|
|
27
|
+
/** PoolCreationDisabled: Pool creation is disabled */
|
|
28
|
+
export const SEND_DEX_ERROR__POOL_CREATION_DISABLED = 0x1775; // 6005
|
|
29
|
+
/** InvalidPoolState: Invalid pool state */
|
|
30
|
+
export const SEND_DEX_ERROR__INVALID_POOL_STATE = 0x1776; // 6006
|
|
31
|
+
/** InvalidDeposit: Invalid deposit */
|
|
32
|
+
export const SEND_DEX_ERROR__INVALID_DEPOSIT = 0x1777; // 6007
|
|
33
|
+
/** InvalidPoolBalance: Invalid pool balance */
|
|
34
|
+
export const SEND_DEX_ERROR__INVALID_POOL_BALANCE = 0x1778; // 6008
|
|
35
|
+
/** InsufficientPoolBalance: Insufficient pool balance */
|
|
36
|
+
export const SEND_DEX_ERROR__INSUFFICIENT_POOL_BALANCE = 0x1779; // 6009
|
|
37
|
+
/** InvalidAuthority: Invalid authority */
|
|
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
|
|
41
|
+
/** InvalidPlatformConfig: Platform config cannot be the default address */
|
|
42
|
+
export const SEND_DEX_ERROR__INVALID_PLATFORM_CONFIG = 0x177c; // 6012
|
|
43
|
+
/** ProgramPaused: Program is paused */
|
|
44
|
+
export const SEND_DEX_ERROR__PROGRAM_PAUSED = 0x1b58; // 7000
|
|
45
|
+
/** Unauthorized: Unauthorized */
|
|
46
|
+
export const SEND_DEX_ERROR__UNAUTHORIZED = 0x1b59; // 7001
|
|
47
|
+
/** ArithmeticOverflow: Arithmetic overflow */
|
|
48
|
+
export const SEND_DEX_ERROR__ARITHMETIC_OVERFLOW = 0x1b5a; // 7002
|
|
49
|
+
/** InvalidPythAccount: Invalid Pyth price account */
|
|
50
|
+
export const SEND_DEX_ERROR__INVALID_PYTH_ACCOUNT = 0x1b5b; // 7003
|
|
51
|
+
/** InvalidPythFeed: Invalid Pyth feed ID */
|
|
52
|
+
export const SEND_DEX_ERROR__INVALID_PYTH_FEED = 0x1b5c; // 7004
|
|
53
|
+
/** InvalidSlug: Invalid slug: must be non-empty, <= max_len bytes, lowercase alphanumeric or underscore */
|
|
54
|
+
export const SEND_DEX_ERROR__INVALID_SLUG = 0x1b5d; // 7005
|
|
55
|
+
/** TextTooLong: Text too long */
|
|
56
|
+
export const SEND_DEX_ERROR__TEXT_TOO_LONG = 0x1b5e; // 7006
|
|
57
|
+
/** UserTokenAccountWrongProgram: User token account owned by the wrong token program */
|
|
58
|
+
export const SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_PROGRAM = 0x1b5f; // 7007
|
|
59
|
+
/** UserTokenAccountInvalid: User token account is not an initialized token account */
|
|
60
|
+
export const SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_INVALID = 0x1b60; // 7008
|
|
61
|
+
/** UserTokenAccountWrongMint: User token account mint does not match the trade */
|
|
62
|
+
export const SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT = 0x1b61; // 7009
|
|
63
|
+
/** UserTokenAccountWrongAuthority: User token account is not owned by the trading user */
|
|
64
|
+
export const SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY = 0x1b62; // 7010
|
|
65
|
+
/** NothingToClaim: Nothing to claim */
|
|
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
|
|
69
|
+
/** QuoteMintPriceUnset: Quote mint has no USDC price on its nexus reward state */
|
|
70
|
+
export const SEND_DEX_ERROR__QUOTE_MINT_PRICE_UNSET = 0x1b65; // 7013
|
|
71
|
+
/** TransferFeeNotSettleable: Token-2022 transfer fee schedule cannot settle the exact amount */
|
|
72
|
+
export const SEND_DEX_ERROR__TRANSFER_FEE_NOT_SETTLEABLE = 0x1b66; // 7014
|
|
73
|
+
/** InsufficientLiquidity: Insufficient liquidity */
|
|
74
|
+
export const SEND_DEX_ERROR__INSUFFICIENT_LIQUIDITY = 0x1bbc; // 7100
|
|
75
|
+
/** InvalidAmount: Invalid amount */
|
|
76
|
+
export const SEND_DEX_ERROR__INVALID_AMOUNT = 0x1bbd; // 7101
|
|
77
|
+
|
|
78
|
+
export type SendDexError =
|
|
79
|
+
| typeof SEND_DEX_ERROR__ARITHMETIC_OVERFLOW
|
|
80
|
+
| typeof SEND_DEX_ERROR__INSUFFICIENT_BALANCE
|
|
81
|
+
| typeof SEND_DEX_ERROR__INSUFFICIENT_LIQUIDITY
|
|
82
|
+
| typeof SEND_DEX_ERROR__INSUFFICIENT_POOL_BALANCE
|
|
83
|
+
| typeof SEND_DEX_ERROR__INVALID_AMOUNT
|
|
84
|
+
| typeof SEND_DEX_ERROR__INVALID_AUTHORITY
|
|
85
|
+
| typeof SEND_DEX_ERROR__INVALID_BASE_MINT
|
|
86
|
+
| typeof SEND_DEX_ERROR__INVALID_CREATOR_HASH
|
|
87
|
+
| typeof SEND_DEX_ERROR__INVALID_CREATOR_ID
|
|
88
|
+
| typeof SEND_DEX_ERROR__INVALID_DEPOSIT
|
|
89
|
+
| typeof SEND_DEX_ERROR__INVALID_PLATFORM_CONFIG
|
|
90
|
+
| typeof SEND_DEX_ERROR__INVALID_POOL_BALANCE
|
|
91
|
+
| typeof SEND_DEX_ERROR__INVALID_POOL_STATE
|
|
92
|
+
| typeof SEND_DEX_ERROR__INVALID_PYTH_ACCOUNT
|
|
93
|
+
| typeof SEND_DEX_ERROR__INVALID_PYTH_FEED
|
|
94
|
+
| typeof SEND_DEX_ERROR__INVALID_QUOTE_MINT
|
|
95
|
+
| typeof SEND_DEX_ERROR__INVALID_SLUG
|
|
96
|
+
| typeof SEND_DEX_ERROR__NOTHING_TO_CLAIM
|
|
97
|
+
| typeof SEND_DEX_ERROR__POOL_CREATION_DISABLED
|
|
98
|
+
| typeof SEND_DEX_ERROR__POOL_PAUSED
|
|
99
|
+
| typeof SEND_DEX_ERROR__PROGRAM_PAUSED
|
|
100
|
+
| typeof SEND_DEX_ERROR__QUOTE_MINT_PRICE_UNSET
|
|
101
|
+
| typeof SEND_DEX_ERROR__SLIPPAGE_EXCEEDED
|
|
102
|
+
| typeof SEND_DEX_ERROR__TEXT_TOO_LONG
|
|
103
|
+
| typeof SEND_DEX_ERROR__TRANSFER_FEE_NOT_SETTLEABLE
|
|
104
|
+
| typeof SEND_DEX_ERROR__UNAUTHORIZED
|
|
105
|
+
| typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_INVALID
|
|
106
|
+
| typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY
|
|
107
|
+
| typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT
|
|
108
|
+
| typeof SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_PROGRAM;
|
|
109
|
+
|
|
110
|
+
export const sendDexErrorMessages: Record<SendDexError, string> = {
|
|
111
|
+
[SEND_DEX_ERROR__ARITHMETIC_OVERFLOW]: `Arithmetic overflow`,
|
|
112
|
+
[SEND_DEX_ERROR__INSUFFICIENT_BALANCE]: `Insufficient balance in source account`,
|
|
113
|
+
[SEND_DEX_ERROR__INSUFFICIENT_LIQUIDITY]: `Insufficient liquidity`,
|
|
114
|
+
[SEND_DEX_ERROR__INSUFFICIENT_POOL_BALANCE]: `Insufficient pool balance`,
|
|
115
|
+
[SEND_DEX_ERROR__INVALID_AMOUNT]: `Invalid amount`,
|
|
116
|
+
[SEND_DEX_ERROR__INVALID_AUTHORITY]: `Invalid authority`,
|
|
117
|
+
[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`,
|
|
120
|
+
[SEND_DEX_ERROR__INVALID_DEPOSIT]: `Invalid deposit`,
|
|
121
|
+
[SEND_DEX_ERROR__INVALID_PLATFORM_CONFIG]: `Platform config cannot be the default address`,
|
|
122
|
+
[SEND_DEX_ERROR__INVALID_POOL_BALANCE]: `Invalid pool balance`,
|
|
123
|
+
[SEND_DEX_ERROR__INVALID_POOL_STATE]: `Invalid pool state`,
|
|
124
|
+
[SEND_DEX_ERROR__INVALID_PYTH_ACCOUNT]: `Invalid Pyth price account`,
|
|
125
|
+
[SEND_DEX_ERROR__INVALID_PYTH_FEED]: `Invalid Pyth feed ID`,
|
|
126
|
+
[SEND_DEX_ERROR__INVALID_QUOTE_MINT]: `Invalid quote mint`,
|
|
127
|
+
[SEND_DEX_ERROR__INVALID_SLUG]: `Invalid slug: must be non-empty, <= max_len bytes, lowercase alphanumeric or underscore`,
|
|
128
|
+
[SEND_DEX_ERROR__NOTHING_TO_CLAIM]: `Nothing to claim`,
|
|
129
|
+
[SEND_DEX_ERROR__POOL_CREATION_DISABLED]: `Pool creation is disabled`,
|
|
130
|
+
[SEND_DEX_ERROR__POOL_PAUSED]: `Pool is paused`,
|
|
131
|
+
[SEND_DEX_ERROR__PROGRAM_PAUSED]: `Program is paused`,
|
|
132
|
+
[SEND_DEX_ERROR__QUOTE_MINT_PRICE_UNSET]: `Quote mint has no USDC price on its nexus reward state`,
|
|
133
|
+
[SEND_DEX_ERROR__SLIPPAGE_EXCEEDED]: `Slippage tolerance exceeded`,
|
|
134
|
+
[SEND_DEX_ERROR__TEXT_TOO_LONG]: `Text too long`,
|
|
135
|
+
[SEND_DEX_ERROR__TRANSFER_FEE_NOT_SETTLEABLE]: `Token-2022 transfer fee schedule cannot settle the exact amount`,
|
|
136
|
+
[SEND_DEX_ERROR__UNAUTHORIZED]: `Unauthorized`,
|
|
137
|
+
[SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_INVALID]: `User token account is not an initialized token account`,
|
|
138
|
+
[SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_AUTHORITY]: `User token account is not owned by the trading user`,
|
|
139
|
+
[SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_MINT]: `User token account mint does not match the trade`,
|
|
140
|
+
[SEND_DEX_ERROR__USER_TOKEN_ACCOUNT_WRONG_PROGRAM]: `User token account owned by the wrong token program`,
|
|
141
|
+
} as const;
|
|
142
|
+
|
|
143
|
+
export function getSendDexErrorMessage(code: SendDexError): string {
|
|
144
|
+
return sendDexErrorMessages[code];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function isSendDexError<TProgramErrorCode extends SendDexError>(
|
|
148
|
+
error: unknown,
|
|
149
|
+
transactionMessage: {
|
|
150
|
+
instructions: Record<number, { programAddress: Address }>;
|
|
151
|
+
},
|
|
152
|
+
code?: TProgramErrorCode,
|
|
153
|
+
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
|
|
154
|
+
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
|
|
155
|
+
return isProgramError<TProgramErrorCode>(
|
|
156
|
+
error,
|
|
157
|
+
transactionMessage,
|
|
158
|
+
SEND_DEX_PROGRAM_ADDRESS,
|
|
159
|
+
code,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
fixEncoderSize,
|
|
11
|
+
getBytesEncoder,
|
|
12
|
+
type ReadonlyUint8Array,
|
|
13
|
+
} from '@solana/kit';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Shared event-framing tag prepended to every CPI-framed event.
|
|
17
|
+
*
|
|
18
|
+
* `containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0)` checks whether data is a framed event
|
|
19
|
+
* at all — including event kinds unknown to this program.
|
|
20
|
+
*/
|
|
21
|
+
export const ANCHOR_EVENT_CPI_DISCRIMINATOR: ReadonlyUint8Array =
|
|
22
|
+
new Uint8Array([228, 69, 165, 46, 81, 203, 154, 29]);
|
|
23
|
+
|
|
24
|
+
export function getAnchorEventCpiDiscriminatorBytes(): ReadonlyUint8Array {
|
|
25
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
26
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
fixEncoderSize,
|
|
12
|
+
getAddressDecoder,
|
|
13
|
+
getBytesEncoder,
|
|
14
|
+
getI64Decoder,
|
|
15
|
+
getStructDecoder,
|
|
16
|
+
getU64Decoder,
|
|
17
|
+
type Address,
|
|
18
|
+
type FixedSizeDecoder,
|
|
19
|
+
type ReadonlyUint8Array,
|
|
20
|
+
} from '@solana/kit';
|
|
21
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
22
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
23
|
+
|
|
24
|
+
export const CREATOR_CLAIM_EVENT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
25
|
+
new Uint8Array([232, 58, 157, 141, 123, 5, 142, 9]);
|
|
26
|
+
|
|
27
|
+
export function getCreatorClaimEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
28
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
29
|
+
CREATOR_CLAIM_EVENT_DISCRIMINATOR,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type CreatorClaimEvent = {
|
|
34
|
+
pool: Address;
|
|
35
|
+
baseMint: Address;
|
|
36
|
+
quoteMint: Address;
|
|
37
|
+
platformConfig: Address;
|
|
38
|
+
coinCreator: Address;
|
|
39
|
+
creatorFeeConfig: Address;
|
|
40
|
+
claimer: Address;
|
|
41
|
+
destinationOwner: Address;
|
|
42
|
+
amount: bigint;
|
|
43
|
+
quoteTransferFee: bigint;
|
|
44
|
+
timestamp: bigint;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let getCreatorClaimEventDecoderCache:
|
|
48
|
+
| FixedSizeDecoder<CreatorClaimEvent>
|
|
49
|
+
| undefined;
|
|
50
|
+
|
|
51
|
+
export function getCreatorClaimEventDecoder(): FixedSizeDecoder<CreatorClaimEvent> {
|
|
52
|
+
return (getCreatorClaimEventDecoderCache ??= getStructDecoder([
|
|
53
|
+
['pool', getAddressDecoder()],
|
|
54
|
+
['baseMint', getAddressDecoder()],
|
|
55
|
+
['quoteMint', getAddressDecoder()],
|
|
56
|
+
['platformConfig', getAddressDecoder()],
|
|
57
|
+
['coinCreator', getAddressDecoder()],
|
|
58
|
+
['creatorFeeConfig', getAddressDecoder()],
|
|
59
|
+
['claimer', getAddressDecoder()],
|
|
60
|
+
['destinationOwner', getAddressDecoder()],
|
|
61
|
+
['amount', getU64Decoder()],
|
|
62
|
+
['quoteTransferFee', getU64Decoder()],
|
|
63
|
+
['timestamp', getI64Decoder()],
|
|
64
|
+
]));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
69
|
+
* {@link CreatorClaimEvent}, without decoding. Never throws.
|
|
70
|
+
*
|
|
71
|
+
* Returns `false` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
72
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
73
|
+
*
|
|
74
|
+
* @see parseCreatorClaimEvent to decode the matching data
|
|
75
|
+
*/
|
|
76
|
+
export function isCreatorClaimEvent(
|
|
77
|
+
event:
|
|
78
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
79
|
+
| ReadonlyUint8Array,
|
|
80
|
+
): boolean {
|
|
81
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
82
|
+
return false;
|
|
83
|
+
const data = 'data' in event ? event.data : event;
|
|
84
|
+
return (
|
|
85
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
86
|
+
containsBytes(data, CREATOR_CLAIM_EVENT_DISCRIMINATOR, 8)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Parses raw event data as a {@link CreatorClaimEvent}. Returns `null` on framing or discriminator
|
|
92
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
93
|
+
*
|
|
94
|
+
* Returns `null` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
95
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
96
|
+
*
|
|
97
|
+
* @see isCreatorClaimEvent to check without decoding
|
|
98
|
+
* @see identifySendDexEvent to identify any program event
|
|
99
|
+
* @see parseSendDexEvent
|
|
100
|
+
*/
|
|
101
|
+
export function parseCreatorClaimEvent(
|
|
102
|
+
event:
|
|
103
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
104
|
+
| ReadonlyUint8Array,
|
|
105
|
+
): CreatorClaimEvent | null {
|
|
106
|
+
const checkedEvent =
|
|
107
|
+
'data' in event
|
|
108
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
109
|
+
: event;
|
|
110
|
+
if (!isCreatorClaimEvent(checkedEvent)) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
114
|
+
return getCreatorClaimEventDecoder().decode(
|
|
115
|
+
data,
|
|
116
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
117
|
+
CREATOR_CLAIM_EVENT_DISCRIMINATOR.length,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
containsBytes,
|
|
11
|
+
fixEncoderSize,
|
|
12
|
+
getAddressDecoder,
|
|
13
|
+
getBytesEncoder,
|
|
14
|
+
getI64Decoder,
|
|
15
|
+
getStructDecoder,
|
|
16
|
+
getU64Decoder,
|
|
17
|
+
type Address,
|
|
18
|
+
type FixedSizeDecoder,
|
|
19
|
+
type ReadonlyUint8Array,
|
|
20
|
+
} from '@solana/kit';
|
|
21
|
+
import { SEND_DEX_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
22
|
+
import { ANCHOR_EVENT_CPI_DISCRIMINATOR } from './anchorEventCpiDiscriminator.framing.js';
|
|
23
|
+
|
|
24
|
+
export const DEPOSIT_QUOTE_EVENT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
25
|
+
new Uint8Array([56, 85, 51, 82, 217, 252, 229, 94]);
|
|
26
|
+
|
|
27
|
+
export function getDepositQuoteEventDiscriminatorBytes(): ReadonlyUint8Array {
|
|
28
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
29
|
+
DEPOSIT_QUOTE_EVENT_DISCRIMINATOR,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type DepositQuoteEvent = {
|
|
34
|
+
pool: Address;
|
|
35
|
+
baseMint: Address;
|
|
36
|
+
quoteMint: Address;
|
|
37
|
+
user: Address;
|
|
38
|
+
platformConfig: Address;
|
|
39
|
+
amount: bigint;
|
|
40
|
+
baseReserves: bigint;
|
|
41
|
+
quoteReserves: bigint;
|
|
42
|
+
timestamp: bigint;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let getDepositQuoteEventDecoderCache:
|
|
46
|
+
| FixedSizeDecoder<DepositQuoteEvent>
|
|
47
|
+
| undefined;
|
|
48
|
+
|
|
49
|
+
export function getDepositQuoteEventDecoder(): FixedSizeDecoder<DepositQuoteEvent> {
|
|
50
|
+
return (getDepositQuoteEventDecoderCache ??= getStructDecoder([
|
|
51
|
+
['pool', getAddressDecoder()],
|
|
52
|
+
['baseMint', getAddressDecoder()],
|
|
53
|
+
['quoteMint', getAddressDecoder()],
|
|
54
|
+
['user', getAddressDecoder()],
|
|
55
|
+
['platformConfig', getAddressDecoder()],
|
|
56
|
+
['amount', getU64Decoder()],
|
|
57
|
+
['baseReserves', getU64Decoder()],
|
|
58
|
+
['quoteReserves', getU64Decoder()],
|
|
59
|
+
['timestamp', getI64Decoder()],
|
|
60
|
+
]));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether the event data matches the framing and discriminator bytes of a
|
|
65
|
+
* {@link DepositQuoteEvent}, without decoding. Never throws.
|
|
66
|
+
*
|
|
67
|
+
* Returns `false` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
68
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
69
|
+
*
|
|
70
|
+
* @see parseDepositQuoteEvent to decode the matching data
|
|
71
|
+
*/
|
|
72
|
+
export function isDepositQuoteEvent(
|
|
73
|
+
event:
|
|
74
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
75
|
+
| ReadonlyUint8Array,
|
|
76
|
+
): boolean {
|
|
77
|
+
if ('data' in event && event.programAddress !== SEND_DEX_PROGRAM_ADDRESS)
|
|
78
|
+
return false;
|
|
79
|
+
const data = 'data' in event ? event.data : event;
|
|
80
|
+
return (
|
|
81
|
+
containsBytes(data, ANCHOR_EVENT_CPI_DISCRIMINATOR, 0) &&
|
|
82
|
+
containsBytes(data, DEPOSIT_QUOTE_EVENT_DISCRIMINATOR, 8)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Parses raw event data as a {@link DepositQuoteEvent}. Returns `null` on framing or discriminator
|
|
88
|
+
* mismatch; throws if the event matches but its body fails to decode.
|
|
89
|
+
*
|
|
90
|
+
* Returns `null` unless `event.programAddress` is SEND_DEX_PROGRAM_ADDRESS.
|
|
91
|
+
* Raw bytes carry no emitter and SKIP that check.
|
|
92
|
+
*
|
|
93
|
+
* @see isDepositQuoteEvent to check without decoding
|
|
94
|
+
* @see identifySendDexEvent to identify any program event
|
|
95
|
+
* @see parseSendDexEvent
|
|
96
|
+
*/
|
|
97
|
+
export function parseDepositQuoteEvent(
|
|
98
|
+
event:
|
|
99
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
100
|
+
| ReadonlyUint8Array,
|
|
101
|
+
): DepositQuoteEvent | null {
|
|
102
|
+
const checkedEvent =
|
|
103
|
+
'data' in event
|
|
104
|
+
? { data: event.data, programAddress: event.programAddress }
|
|
105
|
+
: event;
|
|
106
|
+
if (!isDepositQuoteEvent(checkedEvent)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const data = 'data' in checkedEvent ? checkedEvent.data : checkedEvent;
|
|
110
|
+
return getDepositQuoteEventDecoder().decode(
|
|
111
|
+
data,
|
|
112
|
+
ANCHOR_EVENT_CPI_DISCRIMINATOR.length +
|
|
113
|
+
DEPOSIT_QUOTE_EVENT_DISCRIMINATOR.length,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export * from './anchorEventCpiDiscriminator.framing.js';
|
|
10
|
+
export * from './creatorClaimEvent.js';
|
|
11
|
+
export * from './depositQuoteEvent.js';
|
|
12
|
+
export * from './poolCreateEvent.js';
|
|
13
|
+
export * from './protocolClaimEvent.js';
|
|
14
|
+
export * from './sendDex.events.js';
|
|
15
|
+
export * from './tokenCreateEvent.js';
|
|
16
|
+
export * from './tradeEvent.js';
|