Skip to content

Commit

Permalink
Update JS client to bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksondoherty committed Aug 11, 2024
1 parent 3c3d630 commit 86c1ffe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions token-group/js/src/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getBytesEncoder,
getStructEncoder,
getTupleEncoder,
getU32Encoder,
getU64Encoder,
transformEncoder,
} from '@solana/codecs';
import { splDiscriminate } from '@solana/spl-type-length-value';
Expand All @@ -28,7 +28,7 @@ export interface InitializeGroupInstruction {
mint: PublicKey;
mintAuthority: PublicKey;
updateAuthority: PublicKey | null;
maxSize: number;
maxSize: bigint;
}

export function createInitializeGroupInstruction(args: InitializeGroupInstruction): TransactionInstruction {
Expand All @@ -46,7 +46,7 @@ export function createInitializeGroupInstruction(args: InitializeGroupInstructio
splDiscriminate('spl_token_group_interface:initialize_token_group'),
getStructEncoder([
['updateAuthority', getPublicKeyEncoder()],
['maxSize', getU32Encoder()],
['maxSize', getU64Encoder()],
]),
).encode({ updateAuthority: updateAuthority ?? SystemProgram.programId, maxSize }),
),
Expand All @@ -57,7 +57,7 @@ export interface UpdateGroupMaxSize {
programId: PublicKey;
group: PublicKey;
updateAuthority: PublicKey;
maxSize: number;
maxSize: bigint;
}

export function createUpdateGroupMaxSizeInstruction(args: UpdateGroupMaxSize): TransactionInstruction {
Expand All @@ -71,7 +71,7 @@ export function createUpdateGroupMaxSizeInstruction(args: UpdateGroupMaxSize): T
data: Buffer.from(
getInstructionEncoder(
splDiscriminate('spl_token_group_interface:update_group_max_size'),
getStructEncoder([['maxSize', getU32Encoder()]]),
getStructEncoder([['maxSize', getU64Encoder()]]),
).encode({ maxSize }),
),
});
Expand Down
10 changes: 5 additions & 5 deletions token-group/js/src/state/tokenGroup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PublicKey } from '@solana/web3.js';
import type { ReadonlyUint8Array } from '@solana/codecs';
import { fixCodecSize, getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs';
import { fixCodecSize, getBytesCodec, getStructCodec, getU64Codec } from '@solana/codecs';

const tokenGroupCodec = getStructCodec([
['updateAuthority', fixCodecSize(getBytesCodec(), 32)],
['mint', fixCodecSize(getBytesCodec(), 32)],
['size', getU32Codec()],
['maxSize', getU32Codec()],
['size', getU64Codec()],
['maxSize', getU64Codec()],
]);

export const TOKEN_GROUP_SIZE = tokenGroupCodec.fixedSize;
Expand All @@ -17,9 +17,9 @@ export interface TokenGroup {
/** The associated mint, used to counter spoofing to be sure that group belongs to a particular mint */
mint: PublicKey;
/** The current number of group members */
size: number;
size: bigint;
/** The maximum number of group members */
maxSize: number;
maxSize: bigint;
}

// Checks if all elements in the array are 0
Expand Down
6 changes: 3 additions & 3 deletions token-group/js/src/state/tokenGroupMember.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PublicKey } from '@solana/web3.js';
import type { ReadonlyUint8Array } from '@solana/codecs';
import { fixCodecSize, getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs';
import { fixCodecSize, getBytesCodec, getStructCodec, getU64Codec } from '@solana/codecs';

const tokenGroupMemberCodec = getStructCodec([
['mint', fixCodecSize(getBytesCodec(), 32)],
['group', fixCodecSize(getBytesCodec(), 32)],
['memberNumber', getU32Codec()],
['memberNumber', getU64Codec()],
]);

export const TOKEN_GROUP_MEMBER_SIZE = tokenGroupMemberCodec.fixedSize;
Expand All @@ -16,7 +16,7 @@ export interface TokenGroupMember {
/** The pubkey of the `TokenGroup` */
group: PublicKey;
/** The member number */
memberNumber: number;
memberNumber: bigint;
}

// Pack TokenGroupMember into byte slab
Expand Down
8 changes: 4 additions & 4 deletions token-group/js/test/instruction.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import type { Decoder } from '@solana/codecs';
import { fixDecoderSize, getBytesDecoder, getStructDecoder, getU32Decoder } from '@solana/codecs';
import { fixDecoderSize, getBytesDecoder, getStructDecoder, getU64Decoder } from '@solana/codecs';
import { splDiscriminate } from '@solana/spl-type-length-value';
import { PublicKey, type TransactionInstruction } from '@solana/web3.js';

Expand Down Expand Up @@ -28,7 +28,7 @@ describe('Token Group Instructions', () => {
const updateAuthority = new PublicKey('44444444444444444444444444444444444444444444');
const mint = new PublicKey('55555555555555555555555555555555555555555555');
const mintAuthority = new PublicKey('66666666666666666666666666666666666666666666');
const maxSize = 100;
const maxSize = BigInt(100);

it('Can create InitializeGroup Instruction', () => {
checkPackUnpack(
Expand All @@ -43,7 +43,7 @@ describe('Token Group Instructions', () => {
splDiscriminate('spl_token_group_interface:initialize_token_group'),
getStructDecoder([
['updateAuthority', fixDecoderSize(getBytesDecoder(), 32)],
['maxSize', getU32Decoder()],
['maxSize', getU64Decoder()],
]),
{ updateAuthority: Uint8Array.from(updateAuthority.toBuffer()), maxSize },
);
Expand All @@ -58,7 +58,7 @@ describe('Token Group Instructions', () => {
maxSize,
}),
splDiscriminate('spl_token_group_interface:update_group_max_size'),
getStructDecoder([['maxSize', getU32Decoder()]]),
getStructDecoder([['maxSize', getU64Decoder()]]),
{ maxSize },
);
});
Expand Down
10 changes: 5 additions & 5 deletions token-group/js/test/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ describe('Token Group State', () => {
checkPackUnpack({
mint: new PublicKey('44444444444444444444444444444444444444444444'),
updateAuthority: new PublicKey('55555555555555555555555555555555555555555555'),
size: 10,
maxSize: 20,
size: BigInt(10),
maxSize: BigInt(20),
});
});

it('Can pack and unpack TokenGroup without updateAuthoritygroup', () => {
checkPackUnpack({
mint: new PublicKey('44444444444444444444444444444444444444444444'),
size: 10,
maxSize: 20,
size: BigInt(10),
maxSize: BigInt(20),
});
});
});
Expand All @@ -40,7 +40,7 @@ describe('Token Group State', () => {
checkPackUnpack({
mint: new PublicKey('55555555555555555555555555555555555555555555'),
group: new PublicKey('66666666666666666666666666666666666666666666'),
memberNumber: 8,
memberNumber: BigInt(8),
});
});
});
Expand Down

0 comments on commit 86c1ffe

Please sign in to comment.