Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Hardcode the discriminators so that you don't have to compute them at runtime #7360

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/pull-request-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ jobs:
name-service,
stake-pool,
token,
token-group,
token-metadata,
token-swap,
]
include:
Expand All @@ -58,8 +56,12 @@ jobs:
node-version: 20.x
- package: single-pool
node-version: 20.5
- package: token-group
node-version: 20.x
- package: token-lending
node-version: 18.5
- package: token-metadata
node-version: 20.x
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
135 changes: 19 additions & 116 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion stake-pool/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"license": "ISC",
"dependencies": {
"@solana/buffer-layout": "^4.0.1",
"@solana/spl-token": "0.4.6",
"@solana/spl-token": "0.4.9",
"@solana/web3.js": "^1.95.3",
"bn.js": "^5.2.0",
"buffer": "^6.0.3",
Expand Down
6 changes: 3 additions & 3 deletions token-group/js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@solana/spl-token-group",
"description": "SPL Token Group Interface JS API",
"version": "0.0.6",
"version": "0.0.7",
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
"repository": "https://github.com/solana-labs/solana-program-library",
"license": "Apache-2.0",
Expand Down Expand Up @@ -46,10 +46,10 @@
"@solana/web3.js": "^1.95.3"
},
"dependencies": {
"@solana/codecs": "2.0.0-rc.1",
"@solana/spl-type-length-value": "0.1.0"
"@solana/codecs": "2.0.0-rc.1"
},
"devDependencies": {
"@solana/spl-type-length-value": "0.2.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR won't pass until this is published.

"@solana/web3.js": "^1.95.3",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.9",
Expand Down
21 changes: 16 additions & 5 deletions token-group/js/src/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
getU64Encoder,
transformEncoder,
} from '@solana/codecs';
import { splDiscriminate } from '@solana/spl-type-length-value';
import { SystemProgram, TransactionInstruction } from '@solana/web3.js';

function getInstructionEncoder<T extends object>(discriminator: Uint8Array, dataEncoder: Encoder<T>): Encoder<T> {
Expand Down Expand Up @@ -43,7 +42,10 @@ export function createInitializeGroupInstruction(args: InitializeGroupInstructio
],
data: Buffer.from(
getInstructionEncoder(
splDiscriminate('spl_token_group_interface:initialize_token_group'),
new Uint8Array([
/* await splDiscriminate('spl_token_group_interface:initialize_token_group') */
121, 113, 108, 39, 54, 51, 0, 4,
]),
getStructEncoder([
['updateAuthority', getPublicKeyEncoder()],
['maxSize', getU64Encoder()],
Expand All @@ -70,7 +72,10 @@ export function createUpdateGroupMaxSizeInstruction(args: UpdateGroupMaxSize): T
],
data: Buffer.from(
getInstructionEncoder(
splDiscriminate('spl_token_group_interface:update_group_max_size'),
new Uint8Array([
/* await splDiscriminate('spl_token_group_interface:update_group_max_size') */
108, 37, 171, 143, 248, 30, 18, 110,
]),
getStructEncoder([['maxSize', getU64Encoder()]]),
).encode({ maxSize }),
),
Expand All @@ -95,7 +100,10 @@ export function createUpdateGroupAuthorityInstruction(args: UpdateGroupAuthority
],
data: Buffer.from(
getInstructionEncoder(
splDiscriminate('spl_token_group_interface:update_authority'),
new Uint8Array([
/* await splDiscriminate('spl_token_group_interface:update_authority') */
161, 105, 88, 1, 237, 221, 216, 203,
]),
getStructEncoder([['newAuthority', getPublicKeyEncoder()]]),
).encode({ newAuthority: newAuthority ?? SystemProgram.programId }),
),
Expand Down Expand Up @@ -125,7 +133,10 @@ export function createInitializeMemberInstruction(args: InitializeMember): Trans
],
data: Buffer.from(
getInstructionEncoder(
splDiscriminate('spl_token_group_interface:initialize_member'),
new Uint8Array([
/* await splDiscriminate('spl_token_group_interface:initialize_member') */
152, 32, 222, 176, 223, 237, 116, 134,
]),
getStructEncoder([]),
).encode({}),
),
Expand Down
Loading