@send-fun/sdk 1.0.1 → 1.2.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 +13 -5
- package/dist/index.cjs +797 -369
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +596 -94
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +596 -94
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +527 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -6
- package/src/dex/generated/accounts/globalConfig.ts +39 -2
- package/src/dex/generated/accounts/pool.ts +41 -2
- package/src/dex/generated/accounts/rewardAccrual.ts +39 -2
- package/src/dex/generated/index.ts +1 -0
- package/src/dex/generated/instructions/buyExactIn.ts +1 -1
- package/src/dex/generated/instructions/buyExactOut.ts +1 -1
- package/src/dex/generated/instructions/claimCreatorFees.ts +1 -1
- package/src/dex/generated/instructions/claimProtocolFees.ts +1 -1
- package/src/dex/generated/instructions/sellExactIn.ts +1 -1
- package/src/dex/generated/instructions/sellExactOut.ts +1 -1
- package/src/dex/generated/plugins/sendDex.ts +1 -1
- package/src/dex/generated/shared/index.ts +52 -0
- package/src/dex/trade.ts +12 -13
- package/src/launchpad/create.ts +8 -8
- package/src/launchpad/generated/accounts/bondingCurve.ts +39 -2
- package/src/launchpad/generated/accounts/globalConfig.ts +39 -2
- package/src/launchpad/generated/accounts/rewardAccrual.ts +39 -2
- package/src/launchpad/generated/index.ts +1 -0
- package/src/launchpad/generated/instructions/buyExactIn.ts +1 -1
- package/src/launchpad/generated/instructions/buyExactOut.ts +1 -1
- package/src/launchpad/generated/instructions/claimCreatorFees.ts +1 -1
- package/src/launchpad/generated/instructions/claimProtocolFees.ts +1 -1
- package/src/launchpad/generated/instructions/createToken.ts +1 -1
- package/src/launchpad/generated/instructions/migrate.ts +1 -1
- package/src/launchpad/generated/instructions/sellExactIn.ts +1 -1
- package/src/launchpad/generated/instructions/sellExactOut.ts +1 -1
- package/src/launchpad/generated/plugins/sendLaunchpad.ts +1 -1
- package/src/launchpad/generated/shared/index.ts +52 -0
- package/src/launchpad/migrate.ts +1 -1
- 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 +5 -3
- package/src/nexus/generated/accounts/altRegistry.ts +41 -2
- package/src/nexus/generated/accounts/creatorFeeConfig.ts +39 -2
- package/src/nexus/generated/accounts/feePreset.ts +41 -2
- package/src/nexus/generated/accounts/globalConfig.ts +39 -2
- package/src/nexus/generated/accounts/partnerConfig.ts +39 -2
- package/src/nexus/generated/accounts/partnerMetadata.ts +39 -2
- package/src/nexus/generated/accounts/rewardState.ts +41 -2
- package/src/nexus/generated/accounts/stakingConfig.ts +39 -2
- package/src/nexus/generated/accounts/userRewardDebt.ts +39 -2
- package/src/nexus/generated/accounts/userStakePosition.ts +39 -2
- package/src/nexus/generated/index.ts +1 -0
- package/src/nexus/generated/instructions/claim.ts +1 -1
- package/src/nexus/generated/instructions/createUserRewardDebt.ts +1 -1
- package/src/nexus/generated/instructions/settle.ts +1 -1
- package/src/nexus/generated/instructions/stake.ts +1 -1
- package/src/nexus/generated/instructions/unstake.ts +1 -1
- package/src/nexus/generated/plugins/sendNexus.ts +1 -1
- package/src/nexus/generated/shared/index.ts +52 -0
- 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/creator-hash.ts +6 -3
- package/src/utils/index.ts +2 -0
- package/src/utils/mint-info.ts +8 -7
- package/src/utils/partner.ts +1 -1
- package/src/utils/pda.ts +1 -1
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
type ReadonlyUint8Array,
|
|
41
41
|
} from '@solana/kit';
|
|
42
42
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
43
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
43
44
|
import {
|
|
44
45
|
getAuthPlatformEntryDecoder,
|
|
45
46
|
getAuthPlatformEntryEncoder,
|
|
@@ -110,9 +111,25 @@ export function getGlobalConfigCodec(): Codec<GlobalConfigArgs, GlobalConfig> {
|
|
|
110
111
|
return combineCodec(getGlobalConfigEncoder(), getGlobalConfigDecoder());
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
|
|
116
|
+
* does not match.
|
|
117
|
+
*
|
|
118
|
+
* Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
|
|
119
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
120
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
121
|
+
*/
|
|
113
122
|
export function decodeGlobalConfig<TAddress extends string = string>(
|
|
114
123
|
encodedAccount: EncodedAccount<TAddress>,
|
|
115
124
|
): Account<GlobalConfig, TAddress>;
|
|
125
|
+
/**
|
|
126
|
+
* Decodes a `GlobalConfig` account, throwing when another program owns it or its discriminator
|
|
127
|
+
* does not match.
|
|
128
|
+
*
|
|
129
|
+
* Unlike {@link fetchMaybeGlobalConfig}, this throws for an address that only holds lamports rather
|
|
130
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
131
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
132
|
+
*/
|
|
116
133
|
export function decodeGlobalConfig<TAddress extends string = string>(
|
|
117
134
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
118
135
|
): MaybeAccount<GlobalConfig, TAddress>;
|
|
@@ -143,6 +160,7 @@ export function decodeGlobalConfig<TAddress extends string = string>(
|
|
|
143
160
|
);
|
|
144
161
|
}
|
|
145
162
|
|
|
163
|
+
/** Fetches a `GlobalConfig` account, throwing when it does not exist or only holds lamports. */
|
|
146
164
|
export async function fetchGlobalConfig<TAddress extends string = string>(
|
|
147
165
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
148
166
|
address: Address<TAddress>,
|
|
@@ -153,15 +171,25 @@ export async function fetchGlobalConfig<TAddress extends string = string>(
|
|
|
153
171
|
return maybeAccount;
|
|
154
172
|
}
|
|
155
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Fetches a `GlobalConfig` account, or the non-existing variant when the address holds no
|
|
176
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
177
|
+
* {@link decodeGlobalConfig} throws for a lamports-only account instead.
|
|
178
|
+
*/
|
|
156
179
|
export async function fetchMaybeGlobalConfig<TAddress extends string = string>(
|
|
157
180
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
158
181
|
address: Address<TAddress>,
|
|
159
182
|
config?: FetchAccountConfig,
|
|
160
183
|
): Promise<MaybeAccount<GlobalConfig, TAddress>> {
|
|
161
184
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
162
|
-
return decodeGlobalConfig(
|
|
185
|
+
return decodeGlobalConfig(
|
|
186
|
+
accountIsCreated(maybeAccount)
|
|
187
|
+
? maybeAccount
|
|
188
|
+
: { address, exists: false },
|
|
189
|
+
);
|
|
163
190
|
}
|
|
164
191
|
|
|
192
|
+
/** Fetches `GlobalConfig` accounts, throwing when any does not exist or only holds lamports. */
|
|
165
193
|
export async function fetchAllGlobalConfig(
|
|
166
194
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
167
195
|
addresses: Array<Address>,
|
|
@@ -176,6 +204,11 @@ export async function fetchAllGlobalConfig(
|
|
|
176
204
|
return maybeAccounts;
|
|
177
205
|
}
|
|
178
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Fetches `GlobalConfig` accounts, with the non-existing variant for each address that holds
|
|
209
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
210
|
+
* {@link decodeGlobalConfig} throws for a lamports-only account instead.
|
|
211
|
+
*/
|
|
179
212
|
export async function fetchAllMaybeGlobalConfig(
|
|
180
213
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
181
214
|
addresses: Array<Address>,
|
|
@@ -183,6 +216,10 @@ export async function fetchAllMaybeGlobalConfig(
|
|
|
183
216
|
): Promise<MaybeAccount<GlobalConfig>[]> {
|
|
184
217
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
185
218
|
return maybeAccounts.map((maybeAccount) =>
|
|
186
|
-
decodeGlobalConfig(
|
|
219
|
+
decodeGlobalConfig(
|
|
220
|
+
accountIsCreated(maybeAccount)
|
|
221
|
+
? maybeAccount
|
|
222
|
+
: { address: maybeAccount.address, exists: false },
|
|
223
|
+
),
|
|
187
224
|
);
|
|
188
225
|
}
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
type ReadonlyUint8Array,
|
|
39
39
|
} from '@solana/kit';
|
|
40
40
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
41
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
41
42
|
import {
|
|
42
43
|
getDexFeesDecoder,
|
|
43
44
|
getDexFeesEncoder,
|
|
@@ -127,9 +128,25 @@ export function getPartnerConfigCodec(): FixedSizeCodec<
|
|
|
127
128
|
return combineCodec(getPartnerConfigEncoder(), getPartnerConfigDecoder());
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Decodes a `PartnerConfig` account, throwing when another program owns it or its discriminator
|
|
133
|
+
* does not match.
|
|
134
|
+
*
|
|
135
|
+
* Unlike {@link fetchMaybePartnerConfig}, this throws for an address that only holds lamports rather
|
|
136
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
137
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
138
|
+
*/
|
|
130
139
|
export function decodePartnerConfig<TAddress extends string = string>(
|
|
131
140
|
encodedAccount: EncodedAccount<TAddress>,
|
|
132
141
|
): Account<PartnerConfig, TAddress>;
|
|
142
|
+
/**
|
|
143
|
+
* Decodes a `PartnerConfig` account, throwing when another program owns it or its discriminator
|
|
144
|
+
* does not match.
|
|
145
|
+
*
|
|
146
|
+
* Unlike {@link fetchMaybePartnerConfig}, this throws for an address that only holds lamports rather
|
|
147
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
148
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
149
|
+
*/
|
|
133
150
|
export function decodePartnerConfig<TAddress extends string = string>(
|
|
134
151
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
135
152
|
): MaybeAccount<PartnerConfig, TAddress>;
|
|
@@ -160,6 +177,7 @@ export function decodePartnerConfig<TAddress extends string = string>(
|
|
|
160
177
|
);
|
|
161
178
|
}
|
|
162
179
|
|
|
180
|
+
/** Fetches a `PartnerConfig` account, throwing when it does not exist or only holds lamports. */
|
|
163
181
|
export async function fetchPartnerConfig<TAddress extends string = string>(
|
|
164
182
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
165
183
|
address: Address<TAddress>,
|
|
@@ -170,15 +188,25 @@ export async function fetchPartnerConfig<TAddress extends string = string>(
|
|
|
170
188
|
return maybeAccount;
|
|
171
189
|
}
|
|
172
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Fetches a `PartnerConfig` account, or the non-existing variant when the address holds no
|
|
193
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
194
|
+
* {@link decodePartnerConfig} throws for a lamports-only account instead.
|
|
195
|
+
*/
|
|
173
196
|
export async function fetchMaybePartnerConfig<TAddress extends string = string>(
|
|
174
197
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
175
198
|
address: Address<TAddress>,
|
|
176
199
|
config?: FetchAccountConfig,
|
|
177
200
|
): Promise<MaybeAccount<PartnerConfig, TAddress>> {
|
|
178
201
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
179
|
-
return decodePartnerConfig(
|
|
202
|
+
return decodePartnerConfig(
|
|
203
|
+
accountIsCreated(maybeAccount)
|
|
204
|
+
? maybeAccount
|
|
205
|
+
: { address, exists: false },
|
|
206
|
+
);
|
|
180
207
|
}
|
|
181
208
|
|
|
209
|
+
/** Fetches `PartnerConfig` accounts, throwing when any does not exist or only holds lamports. */
|
|
182
210
|
export async function fetchAllPartnerConfig(
|
|
183
211
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
184
212
|
addresses: Array<Address>,
|
|
@@ -193,6 +221,11 @@ export async function fetchAllPartnerConfig(
|
|
|
193
221
|
return maybeAccounts;
|
|
194
222
|
}
|
|
195
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Fetches `PartnerConfig` accounts, with the non-existing variant for each address that holds
|
|
226
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
227
|
+
* {@link decodePartnerConfig} throws for a lamports-only account instead.
|
|
228
|
+
*/
|
|
196
229
|
export async function fetchAllMaybePartnerConfig(
|
|
197
230
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
198
231
|
addresses: Array<Address>,
|
|
@@ -200,7 +233,11 @@ export async function fetchAllMaybePartnerConfig(
|
|
|
200
233
|
): Promise<MaybeAccount<PartnerConfig>[]> {
|
|
201
234
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
202
235
|
return maybeAccounts.map((maybeAccount) =>
|
|
203
|
-
decodePartnerConfig(
|
|
236
|
+
decodePartnerConfig(
|
|
237
|
+
accountIsCreated(maybeAccount)
|
|
238
|
+
? maybeAccount
|
|
239
|
+
: { address: maybeAccount.address, exists: false },
|
|
240
|
+
),
|
|
204
241
|
);
|
|
205
242
|
}
|
|
206
243
|
|
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
type ReadonlyUint8Array,
|
|
47
47
|
} from '@solana/kit';
|
|
48
48
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
49
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
49
50
|
|
|
50
51
|
export const PARTNER_METADATA_DISCRIMINATOR: ReadonlyUint8Array =
|
|
51
52
|
new Uint8Array([68, 68, 130, 19, 16, 209, 98, 156]);
|
|
@@ -130,9 +131,25 @@ export function getPartnerMetadataCodec(): Codec<
|
|
|
130
131
|
);
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Decodes a `PartnerMetadata` account, throwing when another program owns it or its discriminator
|
|
136
|
+
* does not match.
|
|
137
|
+
*
|
|
138
|
+
* Unlike {@link fetchMaybePartnerMetadata}, this throws for an address that only holds lamports rather
|
|
139
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
140
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
141
|
+
*/
|
|
133
142
|
export function decodePartnerMetadata<TAddress extends string = string>(
|
|
134
143
|
encodedAccount: EncodedAccount<TAddress>,
|
|
135
144
|
): Account<PartnerMetadata, TAddress>;
|
|
145
|
+
/**
|
|
146
|
+
* Decodes a `PartnerMetadata` account, throwing when another program owns it or its discriminator
|
|
147
|
+
* does not match.
|
|
148
|
+
*
|
|
149
|
+
* Unlike {@link fetchMaybePartnerMetadata}, this throws for an address that only holds lamports rather
|
|
150
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
151
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
152
|
+
*/
|
|
136
153
|
export function decodePartnerMetadata<TAddress extends string = string>(
|
|
137
154
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
138
155
|
): MaybeAccount<PartnerMetadata, TAddress>;
|
|
@@ -169,6 +186,7 @@ export function decodePartnerMetadata<TAddress extends string = string>(
|
|
|
169
186
|
);
|
|
170
187
|
}
|
|
171
188
|
|
|
189
|
+
/** Fetches a `PartnerMetadata` account, throwing when it does not exist or only holds lamports. */
|
|
172
190
|
export async function fetchPartnerMetadata<TAddress extends string = string>(
|
|
173
191
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
174
192
|
address: Address<TAddress>,
|
|
@@ -179,6 +197,11 @@ export async function fetchPartnerMetadata<TAddress extends string = string>(
|
|
|
179
197
|
return maybeAccount;
|
|
180
198
|
}
|
|
181
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Fetches a `PartnerMetadata` account, or the non-existing variant when the address holds no
|
|
202
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
203
|
+
* {@link decodePartnerMetadata} throws for a lamports-only account instead.
|
|
204
|
+
*/
|
|
182
205
|
export async function fetchMaybePartnerMetadata<
|
|
183
206
|
TAddress extends string = string,
|
|
184
207
|
>(
|
|
@@ -187,9 +210,14 @@ export async function fetchMaybePartnerMetadata<
|
|
|
187
210
|
config?: FetchAccountConfig,
|
|
188
211
|
): Promise<MaybeAccount<PartnerMetadata, TAddress>> {
|
|
189
212
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
190
|
-
return decodePartnerMetadata(
|
|
213
|
+
return decodePartnerMetadata(
|
|
214
|
+
accountIsCreated(maybeAccount)
|
|
215
|
+
? maybeAccount
|
|
216
|
+
: { address, exists: false },
|
|
217
|
+
);
|
|
191
218
|
}
|
|
192
219
|
|
|
220
|
+
/** Fetches `PartnerMetadata` accounts, throwing when any does not exist or only holds lamports. */
|
|
193
221
|
export async function fetchAllPartnerMetadata(
|
|
194
222
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
195
223
|
addresses: Array<Address>,
|
|
@@ -204,6 +232,11 @@ export async function fetchAllPartnerMetadata(
|
|
|
204
232
|
return maybeAccounts;
|
|
205
233
|
}
|
|
206
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Fetches `PartnerMetadata` accounts, with the non-existing variant for each address that holds
|
|
237
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
238
|
+
* {@link decodePartnerMetadata} throws for a lamports-only account instead.
|
|
239
|
+
*/
|
|
207
240
|
export async function fetchAllMaybePartnerMetadata(
|
|
208
241
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
209
242
|
addresses: Array<Address>,
|
|
@@ -211,6 +244,10 @@ export async function fetchAllMaybePartnerMetadata(
|
|
|
211
244
|
): Promise<MaybeAccount<PartnerMetadata>[]> {
|
|
212
245
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
213
246
|
return maybeAccounts.map((maybeAccount) =>
|
|
214
|
-
decodePartnerMetadata(
|
|
247
|
+
decodePartnerMetadata(
|
|
248
|
+
accountIsCreated(maybeAccount)
|
|
249
|
+
? maybeAccount
|
|
250
|
+
: { address: maybeAccount.address, exists: false },
|
|
251
|
+
),
|
|
215
252
|
);
|
|
216
253
|
}
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
type ReadonlyUint8Array,
|
|
43
43
|
} from '@solana/kit';
|
|
44
44
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
45
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
45
46
|
|
|
46
47
|
export const REWARD_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
47
48
|
86, 245, 149, 170, 90, 108, 31, 251,
|
|
@@ -129,9 +130,25 @@ export function getRewardStateCodec(): FixedSizeCodec<
|
|
|
129
130
|
return combineCodec(getRewardStateEncoder(), getRewardStateDecoder());
|
|
130
131
|
}
|
|
131
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Decodes a `RewardState` account, throwing when another program owns it or its discriminator
|
|
135
|
+
* does not match.
|
|
136
|
+
*
|
|
137
|
+
* Unlike {@link fetchMaybeRewardState}, this throws for an address that only holds lamports rather
|
|
138
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
139
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
140
|
+
*/
|
|
132
141
|
export function decodeRewardState<TAddress extends string = string>(
|
|
133
142
|
encodedAccount: EncodedAccount<TAddress>,
|
|
134
143
|
): Account<RewardState, TAddress>;
|
|
144
|
+
/**
|
|
145
|
+
* Decodes a `RewardState` account, throwing when another program owns it or its discriminator
|
|
146
|
+
* does not match.
|
|
147
|
+
*
|
|
148
|
+
* Unlike {@link fetchMaybeRewardState}, this throws for an address that only holds lamports rather
|
|
149
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
150
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
151
|
+
*/
|
|
135
152
|
export function decodeRewardState<TAddress extends string = string>(
|
|
136
153
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
137
154
|
): MaybeAccount<RewardState, TAddress>;
|
|
@@ -162,6 +179,7 @@ export function decodeRewardState<TAddress extends string = string>(
|
|
|
162
179
|
);
|
|
163
180
|
}
|
|
164
181
|
|
|
182
|
+
/** Fetches a `RewardState` account, throwing when it does not exist or only holds lamports. */
|
|
165
183
|
export async function fetchRewardState<TAddress extends string = string>(
|
|
166
184
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
167
185
|
address: Address<TAddress>,
|
|
@@ -172,15 +190,25 @@ export async function fetchRewardState<TAddress extends string = string>(
|
|
|
172
190
|
return maybeAccount;
|
|
173
191
|
}
|
|
174
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Fetches a `RewardState` account, or the non-existing variant when the address holds no
|
|
195
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
196
|
+
* {@link decodeRewardState} throws for a lamports-only account instead.
|
|
197
|
+
*/
|
|
175
198
|
export async function fetchMaybeRewardState<TAddress extends string = string>(
|
|
176
199
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
177
200
|
address: Address<TAddress>,
|
|
178
201
|
config?: FetchAccountConfig,
|
|
179
202
|
): Promise<MaybeAccount<RewardState, TAddress>> {
|
|
180
203
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
181
|
-
return decodeRewardState(
|
|
204
|
+
return decodeRewardState(
|
|
205
|
+
accountIsCreated(maybeAccount)
|
|
206
|
+
? maybeAccount
|
|
207
|
+
: { address, exists: false },
|
|
208
|
+
);
|
|
182
209
|
}
|
|
183
210
|
|
|
211
|
+
/** Fetches `RewardState` accounts, throwing when any does not exist or only holds lamports. */
|
|
184
212
|
export async function fetchAllRewardState(
|
|
185
213
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
186
214
|
addresses: Array<Address>,
|
|
@@ -195,13 +223,24 @@ export async function fetchAllRewardState(
|
|
|
195
223
|
return maybeAccounts;
|
|
196
224
|
}
|
|
197
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Fetches `RewardState` accounts, with the non-existing variant for each address that holds
|
|
228
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
229
|
+
* {@link decodeRewardState} throws for a lamports-only account instead.
|
|
230
|
+
*/
|
|
198
231
|
export async function fetchAllMaybeRewardState(
|
|
199
232
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
200
233
|
addresses: Array<Address>,
|
|
201
234
|
config?: FetchAccountsConfig,
|
|
202
235
|
): Promise<MaybeAccount<RewardState>[]> {
|
|
203
236
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
204
|
-
return maybeAccounts.map((maybeAccount) =>
|
|
237
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
238
|
+
decodeRewardState(
|
|
239
|
+
accountIsCreated(maybeAccount)
|
|
240
|
+
? maybeAccount
|
|
241
|
+
: { address: maybeAccount.address, exists: false },
|
|
242
|
+
),
|
|
243
|
+
);
|
|
205
244
|
}
|
|
206
245
|
|
|
207
246
|
export function getRewardStateSize(): number {
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
type ReadonlyUint8Array,
|
|
45
45
|
} from '@solana/kit';
|
|
46
46
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
47
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
47
48
|
|
|
48
49
|
export const STAKING_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
49
50
|
45, 134, 252, 82, 37, 57, 84, 25,
|
|
@@ -115,9 +116,25 @@ export function getStakingConfigCodec(): FixedSizeCodec<
|
|
|
115
116
|
return combineCodec(getStakingConfigEncoder(), getStakingConfigDecoder());
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Decodes a `StakingConfig` account, throwing when another program owns it or its discriminator
|
|
121
|
+
* does not match.
|
|
122
|
+
*
|
|
123
|
+
* Unlike {@link fetchMaybeStakingConfig}, this throws for an address that only holds lamports rather
|
|
124
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
125
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
126
|
+
*/
|
|
118
127
|
export function decodeStakingConfig<TAddress extends string = string>(
|
|
119
128
|
encodedAccount: EncodedAccount<TAddress>,
|
|
120
129
|
): Account<StakingConfig, TAddress>;
|
|
130
|
+
/**
|
|
131
|
+
* Decodes a `StakingConfig` account, throwing when another program owns it or its discriminator
|
|
132
|
+
* does not match.
|
|
133
|
+
*
|
|
134
|
+
* Unlike {@link fetchMaybeStakingConfig}, this throws for an address that only holds lamports rather
|
|
135
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
136
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
137
|
+
*/
|
|
121
138
|
export function decodeStakingConfig<TAddress extends string = string>(
|
|
122
139
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
123
140
|
): MaybeAccount<StakingConfig, TAddress>;
|
|
@@ -148,6 +165,7 @@ export function decodeStakingConfig<TAddress extends string = string>(
|
|
|
148
165
|
);
|
|
149
166
|
}
|
|
150
167
|
|
|
168
|
+
/** Fetches a `StakingConfig` account, throwing when it does not exist or only holds lamports. */
|
|
151
169
|
export async function fetchStakingConfig<TAddress extends string = string>(
|
|
152
170
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
153
171
|
address: Address<TAddress>,
|
|
@@ -158,15 +176,25 @@ export async function fetchStakingConfig<TAddress extends string = string>(
|
|
|
158
176
|
return maybeAccount;
|
|
159
177
|
}
|
|
160
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Fetches a `StakingConfig` account, or the non-existing variant when the address holds no
|
|
181
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
182
|
+
* {@link decodeStakingConfig} throws for a lamports-only account instead.
|
|
183
|
+
*/
|
|
161
184
|
export async function fetchMaybeStakingConfig<TAddress extends string = string>(
|
|
162
185
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
163
186
|
address: Address<TAddress>,
|
|
164
187
|
config?: FetchAccountConfig,
|
|
165
188
|
): Promise<MaybeAccount<StakingConfig, TAddress>> {
|
|
166
189
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
167
|
-
return decodeStakingConfig(
|
|
190
|
+
return decodeStakingConfig(
|
|
191
|
+
accountIsCreated(maybeAccount)
|
|
192
|
+
? maybeAccount
|
|
193
|
+
: { address, exists: false },
|
|
194
|
+
);
|
|
168
195
|
}
|
|
169
196
|
|
|
197
|
+
/** Fetches `StakingConfig` accounts, throwing when any does not exist or only holds lamports. */
|
|
170
198
|
export async function fetchAllStakingConfig(
|
|
171
199
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
172
200
|
addresses: Array<Address>,
|
|
@@ -181,6 +209,11 @@ export async function fetchAllStakingConfig(
|
|
|
181
209
|
return maybeAccounts;
|
|
182
210
|
}
|
|
183
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Fetches `StakingConfig` accounts, with the non-existing variant for each address that holds
|
|
214
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
215
|
+
* {@link decodeStakingConfig} throws for a lamports-only account instead.
|
|
216
|
+
*/
|
|
184
217
|
export async function fetchAllMaybeStakingConfig(
|
|
185
218
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
186
219
|
addresses: Array<Address>,
|
|
@@ -188,7 +221,11 @@ export async function fetchAllMaybeStakingConfig(
|
|
|
188
221
|
): Promise<MaybeAccount<StakingConfig>[]> {
|
|
189
222
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
190
223
|
return maybeAccounts.map((maybeAccount) =>
|
|
191
|
-
decodeStakingConfig(
|
|
224
|
+
decodeStakingConfig(
|
|
225
|
+
accountIsCreated(maybeAccount)
|
|
226
|
+
? maybeAccount
|
|
227
|
+
: { address: maybeAccount.address, exists: false },
|
|
228
|
+
),
|
|
192
229
|
);
|
|
193
230
|
}
|
|
194
231
|
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
type ReadonlyUint8Array,
|
|
45
45
|
} from '@solana/kit';
|
|
46
46
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
47
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
47
48
|
|
|
48
49
|
export const USER_REWARD_DEBT_DISCRIMINATOR: ReadonlyUint8Array =
|
|
49
50
|
new Uint8Array([92, 166, 184, 23, 127, 201, 251, 148]);
|
|
@@ -133,9 +134,25 @@ export function getUserRewardDebtCodec(): FixedSizeCodec<
|
|
|
133
134
|
return combineCodec(getUserRewardDebtEncoder(), getUserRewardDebtDecoder());
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Decodes a `UserRewardDebt` account, throwing when another program owns it or its discriminator
|
|
139
|
+
* does not match.
|
|
140
|
+
*
|
|
141
|
+
* Unlike {@link fetchMaybeUserRewardDebt}, this throws for an address that only holds lamports rather
|
|
142
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
143
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
144
|
+
*/
|
|
136
145
|
export function decodeUserRewardDebt<TAddress extends string = string>(
|
|
137
146
|
encodedAccount: EncodedAccount<TAddress>,
|
|
138
147
|
): Account<UserRewardDebt, TAddress>;
|
|
148
|
+
/**
|
|
149
|
+
* Decodes a `UserRewardDebt` account, throwing when another program owns it or its discriminator
|
|
150
|
+
* does not match.
|
|
151
|
+
*
|
|
152
|
+
* Unlike {@link fetchMaybeUserRewardDebt}, this throws for an address that only holds lamports rather
|
|
153
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
154
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
155
|
+
*/
|
|
139
156
|
export function decodeUserRewardDebt<TAddress extends string = string>(
|
|
140
157
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
141
158
|
): MaybeAccount<UserRewardDebt, TAddress>;
|
|
@@ -170,6 +187,7 @@ export function decodeUserRewardDebt<TAddress extends string = string>(
|
|
|
170
187
|
);
|
|
171
188
|
}
|
|
172
189
|
|
|
190
|
+
/** Fetches a `UserRewardDebt` account, throwing when it does not exist or only holds lamports. */
|
|
173
191
|
export async function fetchUserRewardDebt<TAddress extends string = string>(
|
|
174
192
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
175
193
|
address: Address<TAddress>,
|
|
@@ -180,6 +198,11 @@ export async function fetchUserRewardDebt<TAddress extends string = string>(
|
|
|
180
198
|
return maybeAccount;
|
|
181
199
|
}
|
|
182
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Fetches a `UserRewardDebt` account, or the non-existing variant when the address holds no
|
|
203
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
204
|
+
* {@link decodeUserRewardDebt} throws for a lamports-only account instead.
|
|
205
|
+
*/
|
|
183
206
|
export async function fetchMaybeUserRewardDebt<
|
|
184
207
|
TAddress extends string = string,
|
|
185
208
|
>(
|
|
@@ -188,9 +211,14 @@ export async function fetchMaybeUserRewardDebt<
|
|
|
188
211
|
config?: FetchAccountConfig,
|
|
189
212
|
): Promise<MaybeAccount<UserRewardDebt, TAddress>> {
|
|
190
213
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
191
|
-
return decodeUserRewardDebt(
|
|
214
|
+
return decodeUserRewardDebt(
|
|
215
|
+
accountIsCreated(maybeAccount)
|
|
216
|
+
? maybeAccount
|
|
217
|
+
: { address, exists: false },
|
|
218
|
+
);
|
|
192
219
|
}
|
|
193
220
|
|
|
221
|
+
/** Fetches `UserRewardDebt` accounts, throwing when any does not exist or only holds lamports. */
|
|
194
222
|
export async function fetchAllUserRewardDebt(
|
|
195
223
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
196
224
|
addresses: Array<Address>,
|
|
@@ -205,6 +233,11 @@ export async function fetchAllUserRewardDebt(
|
|
|
205
233
|
return maybeAccounts;
|
|
206
234
|
}
|
|
207
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Fetches `UserRewardDebt` accounts, with the non-existing variant for each address that holds
|
|
238
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
239
|
+
* {@link decodeUserRewardDebt} throws for a lamports-only account instead.
|
|
240
|
+
*/
|
|
208
241
|
export async function fetchAllMaybeUserRewardDebt(
|
|
209
242
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
210
243
|
addresses: Array<Address>,
|
|
@@ -212,7 +245,11 @@ export async function fetchAllMaybeUserRewardDebt(
|
|
|
212
245
|
): Promise<MaybeAccount<UserRewardDebt>[]> {
|
|
213
246
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
214
247
|
return maybeAccounts.map((maybeAccount) =>
|
|
215
|
-
decodeUserRewardDebt(
|
|
248
|
+
decodeUserRewardDebt(
|
|
249
|
+
accountIsCreated(maybeAccount)
|
|
250
|
+
? maybeAccount
|
|
251
|
+
: { address: maybeAccount.address, exists: false },
|
|
252
|
+
),
|
|
216
253
|
);
|
|
217
254
|
}
|
|
218
255
|
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
type ReadonlyUint8Array,
|
|
45
45
|
} from '@solana/kit';
|
|
46
46
|
import { SEND_NEXUS_PROGRAM_ADDRESS } from '../programs/index.js';
|
|
47
|
+
import { accountIsCreated } from '../shared/index.js';
|
|
47
48
|
|
|
48
49
|
export const USER_STAKE_POSITION_DISCRIMINATOR: ReadonlyUint8Array =
|
|
49
50
|
new Uint8Array([123, 46, 248, 17, 240, 135, 201, 17]);
|
|
@@ -124,9 +125,25 @@ export function getUserStakePositionCodec(): FixedSizeCodec<
|
|
|
124
125
|
);
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Decodes a `UserStakePosition` account, throwing when another program owns it or its discriminator
|
|
130
|
+
* does not match.
|
|
131
|
+
*
|
|
132
|
+
* Unlike {@link fetchMaybeUserStakePosition}, this throws for an address that only holds lamports rather
|
|
133
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
134
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
135
|
+
*/
|
|
127
136
|
export function decodeUserStakePosition<TAddress extends string = string>(
|
|
128
137
|
encodedAccount: EncodedAccount<TAddress>,
|
|
129
138
|
): Account<UserStakePosition, TAddress>;
|
|
139
|
+
/**
|
|
140
|
+
* Decodes a `UserStakePosition` account, throwing when another program owns it or its discriminator
|
|
141
|
+
* does not match.
|
|
142
|
+
*
|
|
143
|
+
* Unlike {@link fetchMaybeUserStakePosition}, this throws for an address that only holds lamports rather
|
|
144
|
+
* than returning the non-existing variant: an account passed as existing must never come back as that
|
|
145
|
+
* variant typed as an `Account`. Apply {@link accountIsCreated} first to accounts fetched another way.
|
|
146
|
+
*/
|
|
130
147
|
export function decodeUserStakePosition<TAddress extends string = string>(
|
|
131
148
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
132
149
|
): MaybeAccount<UserStakePosition, TAddress>;
|
|
@@ -163,6 +180,7 @@ export function decodeUserStakePosition<TAddress extends string = string>(
|
|
|
163
180
|
);
|
|
164
181
|
}
|
|
165
182
|
|
|
183
|
+
/** Fetches a `UserStakePosition` account, throwing when it does not exist or only holds lamports. */
|
|
166
184
|
export async function fetchUserStakePosition<TAddress extends string = string>(
|
|
167
185
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
168
186
|
address: Address<TAddress>,
|
|
@@ -177,6 +195,11 @@ export async function fetchUserStakePosition<TAddress extends string = string>(
|
|
|
177
195
|
return maybeAccount;
|
|
178
196
|
}
|
|
179
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Fetches a `UserStakePosition` account, or the non-existing variant when the address holds no
|
|
200
|
+
* account or only lamports (see {@link accountIsCreated}).
|
|
201
|
+
* {@link decodeUserStakePosition} throws for a lamports-only account instead.
|
|
202
|
+
*/
|
|
180
203
|
export async function fetchMaybeUserStakePosition<
|
|
181
204
|
TAddress extends string = string,
|
|
182
205
|
>(
|
|
@@ -185,9 +208,14 @@ export async function fetchMaybeUserStakePosition<
|
|
|
185
208
|
config?: FetchAccountConfig,
|
|
186
209
|
): Promise<MaybeAccount<UserStakePosition, TAddress>> {
|
|
187
210
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
188
|
-
return decodeUserStakePosition(
|
|
211
|
+
return decodeUserStakePosition(
|
|
212
|
+
accountIsCreated(maybeAccount)
|
|
213
|
+
? maybeAccount
|
|
214
|
+
: { address, exists: false },
|
|
215
|
+
);
|
|
189
216
|
}
|
|
190
217
|
|
|
218
|
+
/** Fetches `UserStakePosition` accounts, throwing when any does not exist or only holds lamports. */
|
|
191
219
|
export async function fetchAllUserStakePosition(
|
|
192
220
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
193
221
|
addresses: Array<Address>,
|
|
@@ -202,6 +230,11 @@ export async function fetchAllUserStakePosition(
|
|
|
202
230
|
return maybeAccounts;
|
|
203
231
|
}
|
|
204
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Fetches `UserStakePosition` accounts, with the non-existing variant for each address that holds
|
|
235
|
+
* no account or only lamports (see {@link accountIsCreated}).
|
|
236
|
+
* {@link decodeUserStakePosition} throws for a lamports-only account instead.
|
|
237
|
+
*/
|
|
205
238
|
export async function fetchAllMaybeUserStakePosition(
|
|
206
239
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
207
240
|
addresses: Array<Address>,
|
|
@@ -209,7 +242,11 @@ export async function fetchAllMaybeUserStakePosition(
|
|
|
209
242
|
): Promise<MaybeAccount<UserStakePosition>[]> {
|
|
210
243
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
211
244
|
return maybeAccounts.map((maybeAccount) =>
|
|
212
|
-
decodeUserStakePosition(
|
|
245
|
+
decodeUserStakePosition(
|
|
246
|
+
accountIsCreated(maybeAccount)
|
|
247
|
+
? maybeAccount
|
|
248
|
+
: { address: maybeAccount.address, exists: false },
|
|
249
|
+
),
|
|
213
250
|
);
|
|
214
251
|
}
|
|
215
252
|
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
getAccountMetaFactory,
|
|
42
42
|
getAddressFromResolvedInstructionAccount,
|
|
43
43
|
type ResolvedInstructionAccount,
|
|
44
|
-
} from '@solana/program-client-core';
|
|
44
|
+
} from '@solana/kit/program-client-core';
|
|
45
45
|
import {
|
|
46
46
|
EVENT_AUTHORITY_PDA_ADDRESS,
|
|
47
47
|
findRewardStatePda,
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
getAccountMetaFactory,
|
|
39
39
|
getAddressFromResolvedInstructionAccount,
|
|
40
40
|
type ResolvedInstructionAccount,
|
|
41
|
-
} from '@solana/program-client-core';
|
|
41
|
+
} from '@solana/kit/program-client-core';
|
|
42
42
|
import {
|
|
43
43
|
findRewardStatePda,
|
|
44
44
|
findUserRewardDebtPda,
|