Skip to content

Commit e9835ea

Browse files
committed
Rename types
1 parent a27c609 commit e9835ea

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

sdk/src/sdk.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import type {
2828
import type { InferenceStaking } from "./idl";
2929
import { getIdlWithProgramId, IDL } from "./idl";
3030
import type {
31-
InferenceStakingErrors,
31+
InferenceStakingErrorName,
3232
DecodedStakingProgramInstruction,
33-
InferenceStakingInstructions,
33+
InferenceStakingInstructionName,
3434
InstructionAccountsMap,
3535
OperatorPoolAccountStruct,
3636
PoolOverviewAccountStruct,
@@ -506,7 +506,7 @@ export class InferenceStakingProgramSdk {
506506

507507
static getErrorNameFromTransactionLogs(
508508
logs: string[]
509-
): InferenceStakingErrors | undefined {
509+
): InferenceStakingErrorName | undefined {
510510
for (const log of logs) {
511511
const errorName = IDL.errors.find(
512512
(e) =>
@@ -522,7 +522,7 @@ export class InferenceStakingProgramSdk {
522522

523523
static getErrorNameFromTransactionError(
524524
error: unknown
525-
): InferenceStakingErrors | undefined {
525+
): InferenceStakingErrorName | undefined {
526526
if (error instanceof AnchorError) {
527527
const { errorMessage, errorCode } = error.error;
528528
const errorName = IDL.errors.find(
@@ -538,15 +538,15 @@ export class InferenceStakingProgramSdk {
538538
}
539539

540540
static getErrorMsgFromErrorName(
541-
errorName: InferenceStakingErrors | undefined
541+
errorName: InferenceStakingErrorName | undefined
542542
): string | undefined {
543543
const error = IDL.errors.find((e) => e.name === errorName);
544544
return error?.msg;
545545
}
546546

547547
static getProgramErrorFromTransactionError(
548548
error: unknown
549-
): InferenceStakingErrors | undefined {
549+
): InferenceStakingErrorName | undefined {
550550
const message = error instanceof Error ? error.message : null;
551551
if (message == null) {
552552
return undefined;
@@ -655,10 +655,10 @@ export class InferenceStakingProgramSdk {
655655
throw new Error("Failed to decode instruction");
656656
}
657657

658-
const name = decodedIx.name as InferenceStakingInstructions;
658+
const name = decodedIx.name as InferenceStakingInstructionName;
659659

660660
const { args } =
661-
decodedIx.data as RawInstructionArgsMap[InferenceStakingInstructions];
661+
decodedIx.data as RawInstructionArgsMap[InferenceStakingInstructionName];
662662

663663
const accountsMeta: AccountMeta[] = instruction.accounts.map(
664664
(idx) => {
@@ -679,7 +679,7 @@ export class InferenceStakingProgramSdk {
679679
accountsMeta
680680
);
681681

682-
const accounts: InstructionAccountsMap<InferenceStakingInstructions> =
682+
const accounts: InstructionAccountsMap<InferenceStakingInstructionName> =
683683
{};
684684

685685
for (const account of decodedAccounts?.accounts ?? []) {

sdk/src/types.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ExtractErrorNames<T> = T extends { errors: { name: infer N }[] }
3939
? N
4040
: never;
4141

42-
export type InferenceStakingErrors = ExtractErrorNames<typeof IDL>;
42+
export type InferenceStakingErrorName = ExtractErrorNames<typeof IDL>;
4343

4444
/** ******************************************************************************
4545
* Instruction Types
@@ -51,26 +51,28 @@ type ExtractInstructionNames<T> = T extends {
5151
? N
5252
: never;
5353

54-
export type InferenceStakingInstructions = ExtractInstructionNames<typeof IDL>;
54+
export type InferenceStakingInstructionName = ExtractInstructionNames<
55+
typeof IDL
56+
>;
5557

5658
/** ******************************************************************************
5759
* Decoded Instructions - Fixed for nested args
5860
******************************************************************************* */
5961

6062
// Original args type (what the method expects)
61-
type RawInstructionArgs<T extends InferenceStakingInstructions> =
63+
type RawInstructionArgs<T extends InferenceStakingInstructionName> =
6264
InstructionArgs<T>;
6365

6466
// The raw (Borsch) decoded args structure
6567
export type RawInstructionArgsMap = {
66-
[K in InferenceStakingInstructions]: { args: RawInstructionArgs<K> };
68+
[K in InferenceStakingInstructionName]: { args: RawInstructionArgs<K> };
6769
};
6870

6971
export type InstructionArgsMap = {
70-
[K in InferenceStakingInstructions]: RawInstructionArgs<K>;
72+
[K in InferenceStakingInstructionName]: RawInstructionArgs<K>;
7173
};
7274

73-
export type InstructionAccountNames<T extends InferenceStakingInstructions> =
75+
export type InstructionAccountNames<T extends InferenceStakingInstructionName> =
7476
Extract<
7577
InferenceStaking["instructions"][number],
7678
{ name: T }
@@ -86,14 +88,14 @@ export type AccountMetaWithName = {
8688
isWritable: boolean;
8789
};
8890

89-
export type InstructionAccountsMap<T extends InferenceStakingInstructions> =
91+
export type InstructionAccountsMap<T extends InferenceStakingInstructionName> =
9092
Partial<Record<InstructionAccountNames<T>, AccountMetaWithName>>;
9193

9294
export type DecodedStakingProgramInstruction = {
93-
[K in InferenceStakingInstructions]: {
95+
[K in InferenceStakingInstructionName]: {
9496
name: K;
9597
accounts: InstructionAccountsMap<K>;
9698
args: InstructionArgsMap[K];
9799
instructionIndex: number;
98100
};
99-
}[InferenceStakingInstructions];
101+
}[InferenceStakingInstructionName];

tests/lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Pool } from "pg";
1616

1717
import { TokenEmissionsUtils } from "@sdk/src";
1818
import type {
19-
InferenceStakingErrors,
19+
InferenceStakingErrorName,
2020
OperatorPoolAccountStruct,
2121
StakingRecordAccountStruct,
2222
} from "@sdk/src";
@@ -176,7 +176,7 @@ export const generateRewardsForEpoch = (
176176

177177
export function assertStakingProgramError(
178178
error: unknown,
179-
code: InferenceStakingErrors
179+
code: InferenceStakingErrorName
180180
) {
181181
const errorName =
182182
InferenceStakingProgramSdk.getErrorNameFromTransactionError(error);

0 commit comments

Comments
 (0)