@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,209 @@
|
|
|
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
|
+
getI64Decoder,
|
|
24
|
+
getI64Encoder,
|
|
25
|
+
getStructDecoder,
|
|
26
|
+
getStructEncoder,
|
|
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_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
45
|
+
|
|
46
|
+
export const REWARD_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
47
|
+
86, 245, 149, 170, 90, 108, 31, 251,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
export function getRewardStateDiscriminatorBytes(): ReadonlyUint8Array {
|
|
51
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
52
|
+
REWARD_STATE_DISCRIMINATOR,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type RewardState = {
|
|
57
|
+
discriminator: ReadonlyUint8Array;
|
|
58
|
+
version: number;
|
|
59
|
+
bump: number;
|
|
60
|
+
stakingConfig: Address;
|
|
61
|
+
rewardMint: Address;
|
|
62
|
+
vault: Address;
|
|
63
|
+
totalClaimed: bigint;
|
|
64
|
+
usdcPrice: bigint;
|
|
65
|
+
usdcPriceUpdatedAt: bigint;
|
|
66
|
+
isStablecoin: number;
|
|
67
|
+
disabled: number;
|
|
68
|
+
reserved: ReadonlyUint8Array;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type RewardStateArgs = {
|
|
72
|
+
version: number;
|
|
73
|
+
bump: number;
|
|
74
|
+
stakingConfig: Address;
|
|
75
|
+
rewardMint: Address;
|
|
76
|
+
vault: Address;
|
|
77
|
+
totalClaimed: number | bigint;
|
|
78
|
+
usdcPrice: number | bigint;
|
|
79
|
+
usdcPriceUpdatedAt: number | bigint;
|
|
80
|
+
isStablecoin: number;
|
|
81
|
+
disabled: number;
|
|
82
|
+
reserved: ReadonlyUint8Array;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Gets the encoder for {@link RewardStateArgs} account data. */
|
|
86
|
+
export function getRewardStateEncoder(): FixedSizeEncoder<RewardStateArgs> {
|
|
87
|
+
return transformEncoder(
|
|
88
|
+
getStructEncoder([
|
|
89
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
90
|
+
['version', getU8Encoder()],
|
|
91
|
+
['bump', getU8Encoder()],
|
|
92
|
+
['stakingConfig', getAddressEncoder()],
|
|
93
|
+
['rewardMint', getAddressEncoder()],
|
|
94
|
+
['vault', getAddressEncoder()],
|
|
95
|
+
['totalClaimed', getU64Encoder()],
|
|
96
|
+
['usdcPrice', getU64Encoder()],
|
|
97
|
+
['usdcPriceUpdatedAt', getI64Encoder()],
|
|
98
|
+
['isStablecoin', getU8Encoder()],
|
|
99
|
+
['disabled', getU8Encoder()],
|
|
100
|
+
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
|
|
101
|
+
]),
|
|
102
|
+
(value) => ({ ...value, discriminator: REWARD_STATE_DISCRIMINATOR }),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Gets the decoder for {@link RewardState} account data. */
|
|
107
|
+
export function getRewardStateDecoder(): FixedSizeDecoder<RewardState> {
|
|
108
|
+
return getStructDecoder([
|
|
109
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
110
|
+
['version', getU8Decoder()],
|
|
111
|
+
['bump', getU8Decoder()],
|
|
112
|
+
['stakingConfig', getAddressDecoder()],
|
|
113
|
+
['rewardMint', getAddressDecoder()],
|
|
114
|
+
['vault', getAddressDecoder()],
|
|
115
|
+
['totalClaimed', getU64Decoder()],
|
|
116
|
+
['usdcPrice', getU64Decoder()],
|
|
117
|
+
['usdcPriceUpdatedAt', getI64Decoder()],
|
|
118
|
+
['isStablecoin', getU8Decoder()],
|
|
119
|
+
['disabled', getU8Decoder()],
|
|
120
|
+
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Gets the codec for {@link RewardState} account data. */
|
|
125
|
+
export function getRewardStateCodec(): FixedSizeCodec<
|
|
126
|
+
RewardStateArgs,
|
|
127
|
+
RewardState
|
|
128
|
+
> {
|
|
129
|
+
return combineCodec(getRewardStateEncoder(), getRewardStateDecoder());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function decodeRewardState<TAddress extends string = string>(
|
|
133
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
134
|
+
): Account<RewardState, TAddress>;
|
|
135
|
+
export function decodeRewardState<TAddress extends string = string>(
|
|
136
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
137
|
+
): MaybeAccount<RewardState, TAddress>;
|
|
138
|
+
export function decodeRewardState<TAddress extends string = string>(
|
|
139
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
140
|
+
): Account<RewardState, TAddress> | MaybeAccount<RewardState, TAddress> {
|
|
141
|
+
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
142
|
+
if (encodedAccount.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) {
|
|
143
|
+
const error = new Error(
|
|
144
|
+
`decodeRewardState: 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(encodedAccount.data, REWARD_STATE_DISCRIMINATOR, 0)
|
|
151
|
+
) {
|
|
152
|
+
const error = new Error(
|
|
153
|
+
`decodeRewardState: account ${encodedAccount.address} does not match the RewardState discriminator`,
|
|
154
|
+
);
|
|
155
|
+
error.name = 'AccountDiscriminatorMismatchError';
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return decodeAccount(
|
|
160
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
161
|
+
getRewardStateDecoder(),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function fetchRewardState<TAddress extends string = string>(
|
|
166
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
167
|
+
address: Address<TAddress>,
|
|
168
|
+
config?: FetchAccountConfig,
|
|
169
|
+
): Promise<Account<RewardState, TAddress>> {
|
|
170
|
+
const maybeAccount = await fetchMaybeRewardState(rpc, address, config);
|
|
171
|
+
assertAccountExists(maybeAccount);
|
|
172
|
+
return maybeAccount;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export async function fetchMaybeRewardState<TAddress extends string = string>(
|
|
176
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
177
|
+
address: Address<TAddress>,
|
|
178
|
+
config?: FetchAccountConfig,
|
|
179
|
+
): Promise<MaybeAccount<RewardState, TAddress>> {
|
|
180
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
181
|
+
return decodeRewardState(maybeAccount);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function fetchAllRewardState(
|
|
185
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
186
|
+
addresses: Array<Address>,
|
|
187
|
+
config?: FetchAccountsConfig,
|
|
188
|
+
): Promise<Account<RewardState>[]> {
|
|
189
|
+
const maybeAccounts = await fetchAllMaybeRewardState(
|
|
190
|
+
rpc,
|
|
191
|
+
addresses,
|
|
192
|
+
config,
|
|
193
|
+
);
|
|
194
|
+
assertAccountsExist(maybeAccounts);
|
|
195
|
+
return maybeAccounts;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function fetchAllMaybeRewardState(
|
|
199
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
200
|
+
addresses: Array<Address>,
|
|
201
|
+
config?: FetchAccountsConfig,
|
|
202
|
+
): Promise<MaybeAccount<RewardState>[]> {
|
|
203
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
204
|
+
return maybeAccounts.map((maybeAccount) => decodeRewardState(maybeAccount));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function getRewardStateSize(): number {
|
|
208
|
+
return 196;
|
|
209
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
15
|
+
import { ALT_REGISTRY_DISCRIMINATOR } from './altRegistry.js';
|
|
16
|
+
import { CREATOR_FEE_CONFIG_DISCRIMINATOR } from './creatorFeeConfig.js';
|
|
17
|
+
import { FEE_PRESET_DISCRIMINATOR } from './feePreset.js';
|
|
18
|
+
import { GLOBAL_CONFIG_DISCRIMINATOR } from './globalConfig.js';
|
|
19
|
+
import { PARTNER_CONFIG_DISCRIMINATOR } from './partnerConfig.js';
|
|
20
|
+
import { PARTNER_METADATA_DISCRIMINATOR } from './partnerMetadata.js';
|
|
21
|
+
import { REWARD_STATE_DISCRIMINATOR } from './rewardState.js';
|
|
22
|
+
import { STAKING_CONFIG_DISCRIMINATOR } from './stakingConfig.js';
|
|
23
|
+
import { USER_REWARD_DEBT_DISCRIMINATOR } from './userRewardDebt.js';
|
|
24
|
+
import { USER_STAKE_POSITION_DISCRIMINATOR } from './userStakePosition.js';
|
|
25
|
+
|
|
26
|
+
/** Account kinds of the sendNexus program. */
|
|
27
|
+
export type SendNexusAccountType =
|
|
28
|
+
| 'altRegistry'
|
|
29
|
+
| 'creatorFeeConfig'
|
|
30
|
+
| 'feePreset'
|
|
31
|
+
| 'globalConfig'
|
|
32
|
+
| 'partnerConfig'
|
|
33
|
+
| 'partnerMetadata'
|
|
34
|
+
| 'rewardState'
|
|
35
|
+
| 'stakingConfig'
|
|
36
|
+
| 'userRewardDebt'
|
|
37
|
+
| 'userStakePosition';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Identifies sendNexus account data by its discriminators.
|
|
41
|
+
* Returns `null` when the account belongs to another program or the data matches no known account.
|
|
42
|
+
*/
|
|
43
|
+
export function identifySendNexusAccount(
|
|
44
|
+
account:
|
|
45
|
+
| { data: ReadonlyUint8Array; programAddress: Address }
|
|
46
|
+
| ReadonlyUint8Array,
|
|
47
|
+
): SendNexusAccountType | null {
|
|
48
|
+
if (
|
|
49
|
+
'data' in account &&
|
|
50
|
+
account.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS
|
|
51
|
+
)
|
|
52
|
+
return null;
|
|
53
|
+
const data = 'data' in account ? account.data : account;
|
|
54
|
+
if (containsBytes(data, ALT_REGISTRY_DISCRIMINATOR, 0)) {
|
|
55
|
+
return 'altRegistry';
|
|
56
|
+
}
|
|
57
|
+
if (containsBytes(data, CREATOR_FEE_CONFIG_DISCRIMINATOR, 0)) {
|
|
58
|
+
return 'creatorFeeConfig';
|
|
59
|
+
}
|
|
60
|
+
if (containsBytes(data, FEE_PRESET_DISCRIMINATOR, 0)) {
|
|
61
|
+
return 'feePreset';
|
|
62
|
+
}
|
|
63
|
+
if (containsBytes(data, GLOBAL_CONFIG_DISCRIMINATOR, 0)) {
|
|
64
|
+
return 'globalConfig';
|
|
65
|
+
}
|
|
66
|
+
if (containsBytes(data, PARTNER_CONFIG_DISCRIMINATOR, 0)) {
|
|
67
|
+
return 'partnerConfig';
|
|
68
|
+
}
|
|
69
|
+
if (containsBytes(data, PARTNER_METADATA_DISCRIMINATOR, 0)) {
|
|
70
|
+
return 'partnerMetadata';
|
|
71
|
+
}
|
|
72
|
+
if (containsBytes(data, REWARD_STATE_DISCRIMINATOR, 0)) {
|
|
73
|
+
return 'rewardState';
|
|
74
|
+
}
|
|
75
|
+
if (containsBytes(data, STAKING_CONFIG_DISCRIMINATOR, 0)) {
|
|
76
|
+
return 'stakingConfig';
|
|
77
|
+
}
|
|
78
|
+
if (containsBytes(data, USER_REWARD_DEBT_DISCRIMINATOR, 0)) {
|
|
79
|
+
return 'userRewardDebt';
|
|
80
|
+
}
|
|
81
|
+
if (containsBytes(data, USER_STAKE_POSITION_DISCRIMINATOR, 0)) {
|
|
82
|
+
return 'userStakePosition';
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
getBooleanDecoder,
|
|
22
|
+
getBooleanEncoder,
|
|
23
|
+
getBytesDecoder,
|
|
24
|
+
getBytesEncoder,
|
|
25
|
+
getStructDecoder,
|
|
26
|
+
getStructEncoder,
|
|
27
|
+
getU16Decoder,
|
|
28
|
+
getU16Encoder,
|
|
29
|
+
getU64Decoder,
|
|
30
|
+
getU64Encoder,
|
|
31
|
+
getU8Decoder,
|
|
32
|
+
getU8Encoder,
|
|
33
|
+
transformEncoder,
|
|
34
|
+
type Account,
|
|
35
|
+
type Address,
|
|
36
|
+
type EncodedAccount,
|
|
37
|
+
type FetchAccountConfig,
|
|
38
|
+
type FetchAccountsConfig,
|
|
39
|
+
type FixedSizeCodec,
|
|
40
|
+
type FixedSizeDecoder,
|
|
41
|
+
type FixedSizeEncoder,
|
|
42
|
+
type MaybeAccount,
|
|
43
|
+
type MaybeEncodedAccount,
|
|
44
|
+
type ReadonlyUint8Array,
|
|
45
|
+
} from '@solana/kit';
|
|
46
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
47
|
+
|
|
48
|
+
export const STAKING_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
49
|
+
45, 134, 252, 82, 37, 57, 84, 25,
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export function getStakingConfigDiscriminatorBytes(): ReadonlyUint8Array {
|
|
53
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
54
|
+
STAKING_CONFIG_DISCRIMINATOR,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type StakingConfig = {
|
|
59
|
+
discriminator: ReadonlyUint8Array;
|
|
60
|
+
version: number;
|
|
61
|
+
bump: number;
|
|
62
|
+
stakingMint: Address;
|
|
63
|
+
totalStaked: bigint;
|
|
64
|
+
stakingEnabled: boolean;
|
|
65
|
+
rewardCount: number;
|
|
66
|
+
reserved: ReadonlyUint8Array;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type StakingConfigArgs = {
|
|
70
|
+
version: number;
|
|
71
|
+
bump: number;
|
|
72
|
+
stakingMint: Address;
|
|
73
|
+
totalStaked: number | bigint;
|
|
74
|
+
stakingEnabled: boolean;
|
|
75
|
+
rewardCount: number;
|
|
76
|
+
reserved: ReadonlyUint8Array;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Gets the encoder for {@link StakingConfigArgs} account data. */
|
|
80
|
+
export function getStakingConfigEncoder(): FixedSizeEncoder<StakingConfigArgs> {
|
|
81
|
+
return transformEncoder(
|
|
82
|
+
getStructEncoder([
|
|
83
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
84
|
+
['version', getU8Encoder()],
|
|
85
|
+
['bump', getU8Encoder()],
|
|
86
|
+
['stakingMint', getAddressEncoder()],
|
|
87
|
+
['totalStaked', getU64Encoder()],
|
|
88
|
+
['stakingEnabled', getBooleanEncoder()],
|
|
89
|
+
['rewardCount', getU16Encoder()],
|
|
90
|
+
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
|
|
91
|
+
]),
|
|
92
|
+
(value) => ({ ...value, discriminator: STAKING_CONFIG_DISCRIMINATOR }),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Gets the decoder for {@link StakingConfig} account data. */
|
|
97
|
+
export function getStakingConfigDecoder(): FixedSizeDecoder<StakingConfig> {
|
|
98
|
+
return getStructDecoder([
|
|
99
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
100
|
+
['version', getU8Decoder()],
|
|
101
|
+
['bump', getU8Decoder()],
|
|
102
|
+
['stakingMint', getAddressDecoder()],
|
|
103
|
+
['totalStaked', getU64Decoder()],
|
|
104
|
+
['stakingEnabled', getBooleanDecoder()],
|
|
105
|
+
['rewardCount', getU16Decoder()],
|
|
106
|
+
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Gets the codec for {@link StakingConfig} account data. */
|
|
111
|
+
export function getStakingConfigCodec(): FixedSizeCodec<
|
|
112
|
+
StakingConfigArgs,
|
|
113
|
+
StakingConfig
|
|
114
|
+
> {
|
|
115
|
+
return combineCodec(getStakingConfigEncoder(), getStakingConfigDecoder());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function decodeStakingConfig<TAddress extends string = string>(
|
|
119
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
120
|
+
): Account<StakingConfig, TAddress>;
|
|
121
|
+
export function decodeStakingConfig<TAddress extends string = string>(
|
|
122
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
123
|
+
): MaybeAccount<StakingConfig, TAddress>;
|
|
124
|
+
export function decodeStakingConfig<TAddress extends string = string>(
|
|
125
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
126
|
+
): Account<StakingConfig, TAddress> | MaybeAccount<StakingConfig, TAddress> {
|
|
127
|
+
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
128
|
+
if (encodedAccount.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) {
|
|
129
|
+
const error = new Error(
|
|
130
|
+
`decodeStakingConfig: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_NEXUS_PROGRAM_ADDRESS}`,
|
|
131
|
+
);
|
|
132
|
+
error.name = 'AccountOwnerMismatchError';
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
if (
|
|
136
|
+
!containsBytes(encodedAccount.data, STAKING_CONFIG_DISCRIMINATOR, 0)
|
|
137
|
+
) {
|
|
138
|
+
const error = new Error(
|
|
139
|
+
`decodeStakingConfig: account ${encodedAccount.address} does not match the StakingConfig discriminator`,
|
|
140
|
+
);
|
|
141
|
+
error.name = 'AccountDiscriminatorMismatchError';
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return decodeAccount(
|
|
146
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
147
|
+
getStakingConfigDecoder(),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function fetchStakingConfig<TAddress extends string = string>(
|
|
152
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
153
|
+
address: Address<TAddress>,
|
|
154
|
+
config?: FetchAccountConfig,
|
|
155
|
+
): Promise<Account<StakingConfig, TAddress>> {
|
|
156
|
+
const maybeAccount = await fetchMaybeStakingConfig(rpc, address, config);
|
|
157
|
+
assertAccountExists(maybeAccount);
|
|
158
|
+
return maybeAccount;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function fetchMaybeStakingConfig<TAddress extends string = string>(
|
|
162
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
163
|
+
address: Address<TAddress>,
|
|
164
|
+
config?: FetchAccountConfig,
|
|
165
|
+
): Promise<MaybeAccount<StakingConfig, TAddress>> {
|
|
166
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
167
|
+
return decodeStakingConfig(maybeAccount);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export async function fetchAllStakingConfig(
|
|
171
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
172
|
+
addresses: Array<Address>,
|
|
173
|
+
config?: FetchAccountsConfig,
|
|
174
|
+
): Promise<Account<StakingConfig>[]> {
|
|
175
|
+
const maybeAccounts = await fetchAllMaybeStakingConfig(
|
|
176
|
+
rpc,
|
|
177
|
+
addresses,
|
|
178
|
+
config,
|
|
179
|
+
);
|
|
180
|
+
assertAccountsExist(maybeAccounts);
|
|
181
|
+
return maybeAccounts;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function fetchAllMaybeStakingConfig(
|
|
185
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
186
|
+
addresses: Array<Address>,
|
|
187
|
+
config?: FetchAccountsConfig,
|
|
188
|
+
): Promise<MaybeAccount<StakingConfig>[]> {
|
|
189
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
190
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
191
|
+
decodeStakingConfig(maybeAccount),
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function getStakingConfigSize(): number {
|
|
196
|
+
return 117;
|
|
197
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
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
|
+
getU32Decoder,
|
|
28
|
+
getU32Encoder,
|
|
29
|
+
getU64Decoder,
|
|
30
|
+
getU64Encoder,
|
|
31
|
+
getU8Decoder,
|
|
32
|
+
getU8Encoder,
|
|
33
|
+
transformEncoder,
|
|
34
|
+
type Account,
|
|
35
|
+
type Address,
|
|
36
|
+
type EncodedAccount,
|
|
37
|
+
type FetchAccountConfig,
|
|
38
|
+
type FetchAccountsConfig,
|
|
39
|
+
type FixedSizeCodec,
|
|
40
|
+
type FixedSizeDecoder,
|
|
41
|
+
type FixedSizeEncoder,
|
|
42
|
+
type MaybeAccount,
|
|
43
|
+
type MaybeEncodedAccount,
|
|
44
|
+
type ReadonlyUint8Array,
|
|
45
|
+
} from '@solana/kit';
|
|
46
|
+
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
47
|
+
|
|
48
|
+
export const USER_REWARD_DEBT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
49
|
+
new Uint8Array([92, 166, 184, 23, 127, 201, 251, 148]);
|
|
50
|
+
|
|
51
|
+
export function getUserRewardDebtDiscriminatorBytes(): ReadonlyUint8Array {
|
|
52
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
53
|
+
USER_REWARD_DEBT_DISCRIMINATOR,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type UserRewardDebt = {
|
|
58
|
+
discriminator: ReadonlyUint8Array;
|
|
59
|
+
version: number;
|
|
60
|
+
bump: number;
|
|
61
|
+
user: Address;
|
|
62
|
+
stakingMint: Address;
|
|
63
|
+
rewardMint: Address;
|
|
64
|
+
accSnapshot: bigint;
|
|
65
|
+
claimed: bigint;
|
|
66
|
+
amountSnapshot: bigint;
|
|
67
|
+
settledVersion: number;
|
|
68
|
+
owed: bigint;
|
|
69
|
+
reserved: ReadonlyUint8Array;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type UserRewardDebtArgs = {
|
|
73
|
+
version: number;
|
|
74
|
+
bump: number;
|
|
75
|
+
user: Address;
|
|
76
|
+
stakingMint: Address;
|
|
77
|
+
rewardMint: Address;
|
|
78
|
+
accSnapshot: number | bigint;
|
|
79
|
+
claimed: number | bigint;
|
|
80
|
+
amountSnapshot: number | bigint;
|
|
81
|
+
settledVersion: number;
|
|
82
|
+
owed: number | bigint;
|
|
83
|
+
reserved: ReadonlyUint8Array;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Gets the encoder for {@link UserRewardDebtArgs} account data. */
|
|
87
|
+
export function getUserRewardDebtEncoder(): FixedSizeEncoder<UserRewardDebtArgs> {
|
|
88
|
+
return transformEncoder(
|
|
89
|
+
getStructEncoder([
|
|
90
|
+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
|
|
91
|
+
['version', getU8Encoder()],
|
|
92
|
+
['bump', getU8Encoder()],
|
|
93
|
+
['user', getAddressEncoder()],
|
|
94
|
+
['stakingMint', getAddressEncoder()],
|
|
95
|
+
['rewardMint', getAddressEncoder()],
|
|
96
|
+
['accSnapshot', getU128Encoder()],
|
|
97
|
+
['claimed', getU64Encoder()],
|
|
98
|
+
['amountSnapshot', getU64Encoder()],
|
|
99
|
+
['settledVersion', getU32Encoder()],
|
|
100
|
+
['owed', getU64Encoder()],
|
|
101
|
+
['reserved', fixEncoderSize(getBytesEncoder(), 32)],
|
|
102
|
+
]),
|
|
103
|
+
(value) => ({
|
|
104
|
+
...value,
|
|
105
|
+
discriminator: USER_REWARD_DEBT_DISCRIMINATOR,
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Gets the decoder for {@link UserRewardDebt} account data. */
|
|
111
|
+
export function getUserRewardDebtDecoder(): FixedSizeDecoder<UserRewardDebt> {
|
|
112
|
+
return getStructDecoder([
|
|
113
|
+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
|
|
114
|
+
['version', getU8Decoder()],
|
|
115
|
+
['bump', getU8Decoder()],
|
|
116
|
+
['user', getAddressDecoder()],
|
|
117
|
+
['stakingMint', getAddressDecoder()],
|
|
118
|
+
['rewardMint', getAddressDecoder()],
|
|
119
|
+
['accSnapshot', getU128Decoder()],
|
|
120
|
+
['claimed', getU64Decoder()],
|
|
121
|
+
['amountSnapshot', getU64Decoder()],
|
|
122
|
+
['settledVersion', getU32Decoder()],
|
|
123
|
+
['owed', getU64Decoder()],
|
|
124
|
+
['reserved', fixDecoderSize(getBytesDecoder(), 32)],
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Gets the codec for {@link UserRewardDebt} account data. */
|
|
129
|
+
export function getUserRewardDebtCodec(): FixedSizeCodec<
|
|
130
|
+
UserRewardDebtArgs,
|
|
131
|
+
UserRewardDebt
|
|
132
|
+
> {
|
|
133
|
+
return combineCodec(getUserRewardDebtEncoder(), getUserRewardDebtDecoder());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function decodeUserRewardDebt<TAddress extends string = string>(
|
|
137
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
138
|
+
): Account<UserRewardDebt, TAddress>;
|
|
139
|
+
export function decodeUserRewardDebt<TAddress extends string = string>(
|
|
140
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
141
|
+
): MaybeAccount<UserRewardDebt, TAddress>;
|
|
142
|
+
export function decodeUserRewardDebt<TAddress extends string = string>(
|
|
143
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
144
|
+
): Account<UserRewardDebt, TAddress> | MaybeAccount<UserRewardDebt, TAddress> {
|
|
145
|
+
if (!('exists' in encodedAccount) || encodedAccount.exists) {
|
|
146
|
+
if (encodedAccount.programAddress !== SEND_NEXUS_PROGRAM_ADDRESS) {
|
|
147
|
+
const error = new Error(
|
|
148
|
+
`decodeUserRewardDebt: account ${encodedAccount.address} is owned by ${encodedAccount.programAddress}, expected ${SEND_NEXUS_PROGRAM_ADDRESS}`,
|
|
149
|
+
);
|
|
150
|
+
error.name = 'AccountOwnerMismatchError';
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
if (
|
|
154
|
+
!containsBytes(
|
|
155
|
+
encodedAccount.data,
|
|
156
|
+
USER_REWARD_DEBT_DISCRIMINATOR,
|
|
157
|
+
0,
|
|
158
|
+
)
|
|
159
|
+
) {
|
|
160
|
+
const error = new Error(
|
|
161
|
+
`decodeUserRewardDebt: account ${encodedAccount.address} does not match the UserRewardDebt discriminator`,
|
|
162
|
+
);
|
|
163
|
+
error.name = 'AccountDiscriminatorMismatchError';
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return decodeAccount(
|
|
168
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
169
|
+
getUserRewardDebtDecoder(),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function fetchUserRewardDebt<TAddress extends string = string>(
|
|
174
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
175
|
+
address: Address<TAddress>,
|
|
176
|
+
config?: FetchAccountConfig,
|
|
177
|
+
): Promise<Account<UserRewardDebt, TAddress>> {
|
|
178
|
+
const maybeAccount = await fetchMaybeUserRewardDebt(rpc, address, config);
|
|
179
|
+
assertAccountExists(maybeAccount);
|
|
180
|
+
return maybeAccount;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export async function fetchMaybeUserRewardDebt<
|
|
184
|
+
TAddress extends string = string,
|
|
185
|
+
>(
|
|
186
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
187
|
+
address: Address<TAddress>,
|
|
188
|
+
config?: FetchAccountConfig,
|
|
189
|
+
): Promise<MaybeAccount<UserRewardDebt, TAddress>> {
|
|
190
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
191
|
+
return decodeUserRewardDebt(maybeAccount);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export async function fetchAllUserRewardDebt(
|
|
195
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
196
|
+
addresses: Array<Address>,
|
|
197
|
+
config?: FetchAccountsConfig,
|
|
198
|
+
): Promise<Account<UserRewardDebt>[]> {
|
|
199
|
+
const maybeAccounts = await fetchAllMaybeUserRewardDebt(
|
|
200
|
+
rpc,
|
|
201
|
+
addresses,
|
|
202
|
+
config,
|
|
203
|
+
);
|
|
204
|
+
assertAccountsExist(maybeAccounts);
|
|
205
|
+
return maybeAccounts;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function fetchAllMaybeUserRewardDebt(
|
|
209
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
210
|
+
addresses: Array<Address>,
|
|
211
|
+
config?: FetchAccountsConfig,
|
|
212
|
+
): Promise<MaybeAccount<UserRewardDebt>[]> {
|
|
213
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
214
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
215
|
+
decodeUserRewardDebt(maybeAccount),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function getUserRewardDebtSize(): number {
|
|
220
|
+
return 182;
|
|
221
|
+
}
|