Skip to content

Commit 2e8ce36

Browse files
authored
Export discriminator constants for instructions and accounts (#168)
* Export discriminator constants for instructions and accounts * Add changesets
1 parent 21e2428 commit 2e8ce36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+693
-66
lines changed

.changeset/itchy-mirrors-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@kinobi-so/renderers-js': patch
3+
---
4+
5+
Export discriminator constants for instructions and accounts

.changeset/ten-spies-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@kinobi-so/visitors-core': patch
3+
---
4+
5+
Add `find` helper function to the `NodeStack` class

packages/renderers-js/e2e/anchor/src/generated/accounts/guardV1.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ import {
5757
type TransferAmountRuleArgs,
5858
} from '../types';
5959

60+
export const GUARD_V1_DISCRIMINATOR = new Uint8Array([
61+
185, 149, 156, 78, 245, 108, 172, 68,
62+
]);
63+
64+
export function getGuardV1DiscriminatorBytes() {
65+
return fixEncoderSize(getBytesEncoder(), 8).encode(GUARD_V1_DISCRIMINATOR);
66+
}
67+
6068
export type GuardV1 = {
6169
discriminator: ReadonlyUint8Array;
6270
/** Mint token representing the guard, do not confuse with the mint of the token being transferred. */
@@ -97,10 +105,7 @@ export function getGuardV1Encoder(): Encoder<GuardV1Args> {
97105
getArrayEncoder(getMetadataAdditionalFieldRuleEncoder()),
98106
],
99107
]),
100-
(value) => ({
101-
...value,
102-
discriminator: new Uint8Array([185, 149, 156, 78, 245, 108, 172, 68]),
103-
})
108+
(value) => ({ ...value, discriminator: GUARD_V1_DISCRIMINATOR })
104109
);
105110
}
106111

packages/renderers-js/e2e/anchor/src/generated/instructions/createGuard.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ import {
6666
type TransferAmountRuleArgs,
6767
} from '../types';
6868

69+
export const CREATE_GUARD_DISCRIMINATOR = new Uint8Array([
70+
251, 254, 17, 198, 219, 218, 154, 99,
71+
]);
72+
73+
export function getCreateGuardDiscriminatorBytes() {
74+
return fixEncoderSize(getBytesEncoder(), 8).encode(
75+
CREATE_GUARD_DISCRIMINATOR
76+
);
77+
}
78+
6979
export type CreateGuardInstruction<
7080
TProgram extends string = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
7181
TAccountGuard extends string | IAccountMeta<string> = string,
@@ -150,10 +160,7 @@ export function getCreateGuardInstructionDataEncoder(): Encoder<CreateGuardInstr
150160
getArrayEncoder(getMetadataAdditionalFieldRuleEncoder()),
151161
],
152162
]),
153-
(value) => ({
154-
...value,
155-
discriminator: new Uint8Array([251, 254, 17, 198, 219, 218, 154, 99]),
156-
})
163+
(value) => ({ ...value, discriminator: CREATE_GUARD_DISCRIMINATOR })
157164
);
158165
}
159166

packages/renderers-js/e2e/anchor/src/generated/instructions/execute.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ import {
3737
type ResolvedAccount,
3838
} from '../shared';
3939

40+
export const EXECUTE_DISCRIMINATOR = new Uint8Array([
41+
105, 37, 101, 197, 75, 251, 102, 26,
42+
]);
43+
44+
export function getExecuteDiscriminatorBytes() {
45+
return fixEncoderSize(getBytesEncoder(), 8).encode(EXECUTE_DISCRIMINATOR);
46+
}
47+
4048
export type ExecuteInstruction<
4149
TProgram extends string = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
4250
TAccountSourceAccount extends string | IAccountMeta<string> = string,
@@ -91,10 +99,7 @@ export function getExecuteInstructionDataEncoder(): Encoder<ExecuteInstructionDa
9199
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
92100
['amount', getU64Encoder()],
93101
]),
94-
(value) => ({
95-
...value,
96-
discriminator: new Uint8Array([105, 37, 101, 197, 75, 251, 102, 26]),
97-
})
102+
(value) => ({ ...value, discriminator: EXECUTE_DISCRIMINATOR })
98103
);
99104
}
100105

packages/renderers-js/e2e/anchor/src/generated/instructions/initialize.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ import {
3939
type ResolvedAccount,
4040
} from '../shared';
4141

42+
export const INITIALIZE_DISCRIMINATOR = new Uint8Array([
43+
43, 34, 13, 49, 167, 88, 235, 235,
44+
]);
45+
46+
export function getInitializeDiscriminatorBytes() {
47+
return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_DISCRIMINATOR);
48+
}
49+
4250
export type InitializeInstruction<
4351
TProgram extends string = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
4452
TAccountExtraMetasAccount extends string | IAccountMeta<string> = string,
@@ -85,10 +93,7 @@ export type InitializeInstructionDataArgs = {};
8593
export function getInitializeInstructionDataEncoder(): Encoder<InitializeInstructionDataArgs> {
8694
return transformEncoder(
8795
getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]),
88-
(value) => ({
89-
...value,
90-
discriminator: new Uint8Array([43, 34, 13, 49, 167, 88, 235, 235]),
91-
})
96+
(value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR })
9297
);
9398
}
9499

packages/renderers-js/e2e/anchor/src/generated/instructions/updateGuard.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ import {
5959
type TransferAmountRuleArgs,
6060
} from '../types';
6161

62+
export const UPDATE_GUARD_DISCRIMINATOR = new Uint8Array([
63+
51, 38, 175, 180, 25, 249, 39, 24,
64+
]);
65+
66+
export function getUpdateGuardDiscriminatorBytes() {
67+
return fixEncoderSize(getBytesEncoder(), 8).encode(
68+
UPDATE_GUARD_DISCRIMINATOR
69+
);
70+
}
71+
6272
export type UpdateGuardInstruction<
6373
TProgram extends string = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
6474
TAccountGuard extends string | IAccountMeta<string> = string,
@@ -123,10 +133,7 @@ export function getUpdateGuardInstructionDataEncoder(): Encoder<UpdateGuardInstr
123133
getArrayEncoder(getMetadataAdditionalFieldRuleEncoder()),
124134
],
125135
]),
126-
(value) => ({
127-
...value,
128-
discriminator: new Uint8Array([51, 38, 175, 180, 25, 249, 39, 24]),
129-
})
136+
(value) => ({ ...value, discriminator: UPDATE_GUARD_DISCRIMINATOR })
130137
);
131138
}
132139

packages/renderers-js/e2e/system/src/generated/instructions/advanceNonceAccount.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import {
3030
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
3131
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
3232

33+
export const ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR = 4;
34+
35+
export function getAdvanceNonceAccountDiscriminatorBytes() {
36+
return getU32Encoder().encode(ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR);
37+
}
38+
3339
export type AdvanceNonceAccountInstruction<
3440
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
3541
TAccountNonceAccount extends string | IAccountMeta<string> = string,
@@ -63,7 +69,10 @@ export type AdvanceNonceAccountInstructionDataArgs = {};
6369
export function getAdvanceNonceAccountInstructionDataEncoder(): Encoder<AdvanceNonceAccountInstructionDataArgs> {
6470
return transformEncoder(
6571
getStructEncoder([['discriminator', getU32Encoder()]]),
66-
(value) => ({ ...value, discriminator: 4 })
72+
(value) => ({
73+
...value,
74+
discriminator: ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR,
75+
})
6776
);
6877
}
6978

packages/renderers-js/e2e/system/src/generated/instructions/allocate.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import {
3030
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
3131
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
3232

33+
export const ALLOCATE_DISCRIMINATOR = 8;
34+
35+
export function getAllocateDiscriminatorBytes() {
36+
return getU32Encoder().encode(ALLOCATE_DISCRIMINATOR);
37+
}
38+
3339
export type AllocateInstruction<
3440
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
3541
TAccountNewAccount extends string | IAccountMeta<string> = string,
@@ -56,7 +62,7 @@ export function getAllocateInstructionDataEncoder(): Encoder<AllocateInstruction
5662
['discriminator', getU32Encoder()],
5763
['space', getU64Encoder()],
5864
]),
59-
(value) => ({ ...value, discriminator: 8 })
65+
(value) => ({ ...value, discriminator: ALLOCATE_DISCRIMINATOR })
6066
);
6167
}
6268

packages/renderers-js/e2e/system/src/generated/instructions/allocateWithSeed.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ import {
3737
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
3838
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
3939

40+
export const ALLOCATE_WITH_SEED_DISCRIMINATOR = 9;
41+
42+
export function getAllocateWithSeedDiscriminatorBytes() {
43+
return getU32Encoder().encode(ALLOCATE_WITH_SEED_DISCRIMINATOR);
44+
}
45+
4046
export type AllocateWithSeedInstruction<
4147
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
4248
TAccountNewAccount extends string | IAccountMeta<string> = string,
@@ -81,7 +87,7 @@ export function getAllocateWithSeedInstructionDataEncoder(): Encoder<AllocateWit
8187
['space', getU64Encoder()],
8288
['programAddress', getAddressEncoder()],
8389
]),
84-
(value) => ({ ...value, discriminator: 9 })
90+
(value) => ({ ...value, discriminator: ALLOCATE_WITH_SEED_DISCRIMINATOR })
8591
);
8692
}
8793

0 commit comments

Comments
 (0)