From 86c1ffe509e5a6ab99738f4ab5cf91499019ab00 Mon Sep 17 00:00:00 2001 From: Jackson Doherty Date: Sun, 11 Aug 2024 11:17:11 -0400 Subject: [PATCH] Update JS client to bigint --- token-group/js/src/instruction.ts | 10 +++++----- token-group/js/src/state/tokenGroup.ts | 10 +++++----- token-group/js/src/state/tokenGroupMember.ts | 6 +++--- token-group/js/test/instruction.test.ts | 8 ++++---- token-group/js/test/state.test.ts | 10 +++++----- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/token-group/js/src/instruction.ts b/token-group/js/src/instruction.ts index ff82c9f953a..6d14cbb4b95 100644 --- a/token-group/js/src/instruction.ts +++ b/token-group/js/src/instruction.ts @@ -5,7 +5,7 @@ import { getBytesEncoder, getStructEncoder, getTupleEncoder, - getU32Encoder, + getU64Encoder, transformEncoder, } from '@solana/codecs'; import { splDiscriminate } from '@solana/spl-type-length-value'; @@ -28,7 +28,7 @@ export interface InitializeGroupInstruction { mint: PublicKey; mintAuthority: PublicKey; updateAuthority: PublicKey | null; - maxSize: number; + maxSize: bigint; } export function createInitializeGroupInstruction(args: InitializeGroupInstruction): TransactionInstruction { @@ -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 }), ), @@ -57,7 +57,7 @@ export interface UpdateGroupMaxSize { programId: PublicKey; group: PublicKey; updateAuthority: PublicKey; - maxSize: number; + maxSize: bigint; } export function createUpdateGroupMaxSizeInstruction(args: UpdateGroupMaxSize): TransactionInstruction { @@ -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 }), ), }); diff --git a/token-group/js/src/state/tokenGroup.ts b/token-group/js/src/state/tokenGroup.ts index ecc51254268..c0895e28507 100644 --- a/token-group/js/src/state/tokenGroup.ts +++ b/token-group/js/src/state/tokenGroup.ts @@ -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; @@ -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 diff --git a/token-group/js/src/state/tokenGroupMember.ts b/token-group/js/src/state/tokenGroupMember.ts index 8d49a0316a7..c952c4faaa1 100644 --- a/token-group/js/src/state/tokenGroupMember.ts +++ b/token-group/js/src/state/tokenGroupMember.ts @@ -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; @@ -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 diff --git a/token-group/js/test/instruction.test.ts b/token-group/js/test/instruction.test.ts index ebf26e4d29e..ad8f405d406 100644 --- a/token-group/js/test/instruction.test.ts +++ b/token-group/js/test/instruction.test.ts @@ -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'; @@ -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( @@ -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 }, ); @@ -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 }, ); }); diff --git a/token-group/js/test/state.test.ts b/token-group/js/test/state.test.ts index 36f874b5209..f071de87dc1 100644 --- a/token-group/js/test/state.test.ts +++ b/token-group/js/test/state.test.ts @@ -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), }); }); }); @@ -40,7 +40,7 @@ describe('Token Group State', () => { checkPackUnpack({ mint: new PublicKey('55555555555555555555555555555555555555555555'), group: new PublicKey('66666666666666666666666666666666666666666666'), - memberNumber: 8, + memberNumber: BigInt(8), }); }); });