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

Commit dc89cbe

Browse files
token-group: Increase max size type to u64 (#7130)
* Change max size to u64 in interface * Update interface example and token client * Update token CLI * Update additional token2022 tests * Update collection example * Update JS client to bigint * Update e2e tests * Update additional e2e tests
1 parent 42d465a commit dc89cbe

File tree

18 files changed

+82
-82
lines changed

18 files changed

+82
-82
lines changed

token-collection/program/tests/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub async fn setup_group(
8989
mint: &Keypair,
9090
mint_authority: &Keypair,
9191
update_authority: Option<Pubkey>,
92-
max_size: u32,
92+
max_size: u64,
9393
rent_lamports: u64,
9494
space: usize,
9595
) {

token-collection/program/tests/token_collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ async fn test_token_collection() {
325325
.data;
326326
let state = TlvStateBorrowed::unpack(&buffer).unwrap();
327327
let collection = state.get_first_value::<TokenGroup>().unwrap();
328-
assert_eq!(u32::from(collection.size), 3);
328+
assert_eq!(u64::from(collection.size), 3);
329329

330330
// The "Snakes" collection should have 2 members
331331
let buffer = context
@@ -337,7 +337,7 @@ async fn test_token_collection() {
337337
.data;
338338
let state = TlvStateBorrowed::unpack(&buffer).unwrap();
339339
let collection = state.get_first_value::<TokenGroup>().unwrap();
340-
assert_eq!(u32::from(collection.size), 2);
340+
assert_eq!(u64::from(collection.size), 2);
341341

342342
// The "Python" should be a member of 2 collections
343343
let buffer = context

token-group/example/tests/initialize_member.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,5 @@ async fn test_initialize_group_member() {
256256
let fetched_meta = TlvStateBorrowed::unpack(&member_account.data).unwrap();
257257
let fetched_group_member_state = fetched_meta.get_first_value::<TokenGroupMember>().unwrap();
258258
assert_eq!(fetched_group_member_state.group, group.pubkey());
259-
assert_eq!(u32::from(fetched_group_member_state.member_number), 1);
259+
assert_eq!(u64::from(fetched_group_member_state.member_number), 1);
260260
}

token-group/interface/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ For a group:
9595

9696
```rust
9797
type OptionalNonZeroPubkey = Pubkey; // if all zeroes, interpreted as `None`
98-
type PodU32 = [u8; 4];
98+
type PodU64 = [u8; 8];
9999
type Pubkey = [u8; 32];
100100

101101
/// Type discriminant: [214, 15, 63, 132, 49, 119, 209, 40]
@@ -107,9 +107,9 @@ pub struct TokenGroup {
107107
/// belongs to a particular mint
108108
pub mint: Pubkey,
109109
/// The current number of group members
110-
pub size: PodU32,
110+
pub size: PodU64,
111111
/// The maximum number of group members
112-
pub max_size: PodU32,
112+
pub max_size: PodU64,
113113
}
114114
```
115115

@@ -125,7 +125,7 @@ pub struct TokenGroupMember {
125125
/// The pubkey of the `TokenGroup`
126126
pub group: Pubkey,
127127
/// The member number
128-
pub member_number: PodU32,
128+
pub member_number: PodU64,
129129
}
130130
```
131131

token-group/interface/src/instruction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use {
1111
spl_pod::{
1212
bytemuck::{pod_bytes_of, pod_from_bytes},
1313
optional_keys::OptionalNonZeroPubkey,
14-
primitives::PodU32,
14+
primitives::PodU64,
1515
},
1616
};
1717

@@ -23,7 +23,7 @@ pub struct InitializeGroup {
2323
/// Update authority for the group
2424
pub update_authority: OptionalNonZeroPubkey,
2525
/// The maximum number of group members
26-
pub max_size: PodU32,
26+
pub max_size: PodU64,
2727
}
2828

2929
/// Instruction data for updating the max size of a `Group`
@@ -32,7 +32,7 @@ pub struct InitializeGroup {
3232
#[discriminator_hash_input("spl_token_group_interface:update_group_max_size")]
3333
pub struct UpdateGroupMaxSize {
3434
/// New max size for the group
35-
pub max_size: PodU32,
35+
pub max_size: PodU64,
3636
}
3737

3838
/// Instruction data for updating the authority of a `Group`
@@ -155,7 +155,7 @@ pub fn initialize_group(
155155
mint: &Pubkey,
156156
mint_authority: &Pubkey,
157157
update_authority: Option<Pubkey>,
158-
max_size: u32,
158+
max_size: u64,
159159
) -> Instruction {
160160
let update_authority = OptionalNonZeroPubkey::try_from(update_authority)
161161
.expect("Failed to deserialize `Option<Pubkey>`");
@@ -180,7 +180,7 @@ pub fn update_group_max_size(
180180
program_id: &Pubkey,
181181
group: &Pubkey,
182182
update_authority: &Pubkey,
183-
max_size: u32,
183+
max_size: u64,
184184
) -> Instruction {
185185
let data = TokenGroupInstruction::UpdateGroupMaxSize(UpdateGroupMaxSize {
186186
max_size: max_size.into(),

token-group/interface/src/state.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
bytemuck::{Pod, Zeroable},
66
solana_program::{program_error::ProgramError, pubkey::Pubkey},
77
spl_discriminator::SplDiscriminate,
8-
spl_pod::{error::PodSliceError, optional_keys::OptionalNonZeroPubkey, primitives::PodU32},
8+
spl_pod::{error::PodSliceError, optional_keys::OptionalNonZeroPubkey, primitives::PodU64},
99
};
1010

1111
/// Data struct for a `TokenGroup`
@@ -19,39 +19,39 @@ pub struct TokenGroup {
1919
/// belongs to a particular mint
2020
pub mint: Pubkey,
2121
/// The current number of group members
22-
pub size: PodU32,
22+
pub size: PodU64,
2323
/// The maximum number of group members
24-
pub max_size: PodU32,
24+
pub max_size: PodU64,
2525
}
2626

2727
impl TokenGroup {
2828
/// Creates a new `TokenGroup` state
29-
pub fn new(mint: &Pubkey, update_authority: OptionalNonZeroPubkey, max_size: u32) -> Self {
29+
pub fn new(mint: &Pubkey, update_authority: OptionalNonZeroPubkey, max_size: u64) -> Self {
3030
Self {
3131
mint: *mint,
3232
update_authority,
33-
size: PodU32::default(), // [0, 0, 0, 0]
33+
size: PodU64::default(), // [0, 0, 0, 0, 0, 0, 0, 0]
3434
max_size: max_size.into(),
3535
}
3636
}
3737

3838
/// Updates the max size for a group
39-
pub fn update_max_size(&mut self, new_max_size: u32) -> Result<(), ProgramError> {
39+
pub fn update_max_size(&mut self, new_max_size: u64) -> Result<(), ProgramError> {
4040
// The new max size cannot be less than the current size
41-
if new_max_size < u32::from(self.size) {
41+
if new_max_size < u64::from(self.size) {
4242
return Err(TokenGroupError::SizeExceedsNewMaxSize.into());
4343
}
4444
self.max_size = new_max_size.into();
4545
Ok(())
4646
}
4747

4848
/// Increment the size for a group, returning the new size
49-
pub fn increment_size(&mut self) -> Result<u32, ProgramError> {
49+
pub fn increment_size(&mut self) -> Result<u64, ProgramError> {
5050
// The new size cannot be greater than the max size
51-
let new_size = u32::from(self.size)
51+
let new_size = u64::from(self.size)
5252
.checked_add(1)
5353
.ok_or::<ProgramError>(PodSliceError::CalculationFailure.into())?;
54-
if new_size > u32::from(self.max_size) {
54+
if new_size > u64::from(self.max_size) {
5555
return Err(TokenGroupError::SizeExceedsMaxSize.into());
5656
}
5757
self.size = new_size.into();
@@ -70,11 +70,11 @@ pub struct TokenGroupMember {
7070
/// The pubkey of the `TokenGroup`
7171
pub group: Pubkey,
7272
/// The member number
73-
pub member_number: PodU32,
73+
pub member_number: PodU64,
7474
}
7575
impl TokenGroupMember {
7676
/// Creates a new `TokenGroupMember` state
77-
pub fn new(mint: &Pubkey, group: &Pubkey, member_number: u32) -> Self {
77+
pub fn new(mint: &Pubkey, group: &Pubkey, member_number: u64) -> Self {
7878
Self {
7979
mint: *mint,
8080
group: *group,
@@ -156,7 +156,7 @@ mod tests {
156156

157157
let new_max_size = 30;
158158
group.update_max_size(new_max_size).unwrap();
159-
assert_eq!(u32::from(group.max_size), new_max_size);
159+
assert_eq!(u64::from(group.max_size), new_max_size);
160160

161161
// Change the current size to 30
162162
group.size = 30.into();
@@ -170,7 +170,7 @@ mod tests {
170170

171171
let new_max_size = 30;
172172
group.update_max_size(new_max_size).unwrap();
173-
assert_eq!(u32::from(group.max_size), new_max_size);
173+
assert_eq!(u64::from(group.max_size), new_max_size);
174174
}
175175

176176
#[test]
@@ -183,7 +183,7 @@ mod tests {
183183
};
184184

185185
group.increment_size().unwrap();
186-
assert_eq!(u32::from(group.size), 1);
186+
assert_eq!(u64::from(group.size), 1);
187187

188188
// Try to increase the current size to 2, which is greater than the max size
189189
assert_eq!(

token-group/js/src/instruction.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getBytesEncoder,
66
getStructEncoder,
77
getTupleEncoder,
8-
getU32Encoder,
8+
getU64Encoder,
99
transformEncoder,
1010
} from '@solana/codecs';
1111
import { splDiscriminate } from '@solana/spl-type-length-value';
@@ -28,7 +28,7 @@ export interface InitializeGroupInstruction {
2828
mint: PublicKey;
2929
mintAuthority: PublicKey;
3030
updateAuthority: PublicKey | null;
31-
maxSize: number;
31+
maxSize: bigint;
3232
}
3333

3434
export function createInitializeGroupInstruction(args: InitializeGroupInstruction): TransactionInstruction {
@@ -46,7 +46,7 @@ export function createInitializeGroupInstruction(args: InitializeGroupInstructio
4646
splDiscriminate('spl_token_group_interface:initialize_token_group'),
4747
getStructEncoder([
4848
['updateAuthority', getPublicKeyEncoder()],
49-
['maxSize', getU32Encoder()],
49+
['maxSize', getU64Encoder()],
5050
]),
5151
).encode({ updateAuthority: updateAuthority ?? SystemProgram.programId, maxSize }),
5252
),
@@ -57,7 +57,7 @@ export interface UpdateGroupMaxSize {
5757
programId: PublicKey;
5858
group: PublicKey;
5959
updateAuthority: PublicKey;
60-
maxSize: number;
60+
maxSize: bigint;
6161
}
6262

6363
export function createUpdateGroupMaxSizeInstruction(args: UpdateGroupMaxSize): TransactionInstruction {
@@ -71,7 +71,7 @@ export function createUpdateGroupMaxSizeInstruction(args: UpdateGroupMaxSize): T
7171
data: Buffer.from(
7272
getInstructionEncoder(
7373
splDiscriminate('spl_token_group_interface:update_group_max_size'),
74-
getStructEncoder([['maxSize', getU32Encoder()]]),
74+
getStructEncoder([['maxSize', getU64Encoder()]]),
7575
).encode({ maxSize }),
7676
),
7777
});

token-group/js/src/state/tokenGroup.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { PublicKey } from '@solana/web3.js';
22
import type { ReadonlyUint8Array } from '@solana/codecs';
3-
import { fixCodecSize, getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs';
3+
import { fixCodecSize, getBytesCodec, getStructCodec, getU64Codec } from '@solana/codecs';
44

55
const tokenGroupCodec = getStructCodec([
66
['updateAuthority', fixCodecSize(getBytesCodec(), 32)],
77
['mint', fixCodecSize(getBytesCodec(), 32)],
8-
['size', getU32Codec()],
9-
['maxSize', getU32Codec()],
8+
['size', getU64Codec()],
9+
['maxSize', getU64Codec()],
1010
]);
1111

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

2525
// Checks if all elements in the array are 0

token-group/js/src/state/tokenGroupMember.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { PublicKey } from '@solana/web3.js';
22
import type { ReadonlyUint8Array } from '@solana/codecs';
3-
import { fixCodecSize, getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs';
3+
import { fixCodecSize, getBytesCodec, getStructCodec, getU64Codec } from '@solana/codecs';
44

55
const tokenGroupMemberCodec = getStructCodec([
66
['mint', fixCodecSize(getBytesCodec(), 32)],
77
['group', fixCodecSize(getBytesCodec(), 32)],
8-
['memberNumber', getU32Codec()],
8+
['memberNumber', getU64Codec()],
99
]);
1010

1111
export const TOKEN_GROUP_MEMBER_SIZE = tokenGroupMemberCodec.fixedSize;
@@ -16,7 +16,7 @@ export interface TokenGroupMember {
1616
/** The pubkey of the `TokenGroup` */
1717
group: PublicKey;
1818
/** The member number */
19-
memberNumber: number;
19+
memberNumber: bigint;
2020
}
2121

2222
// Pack TokenGroupMember into byte slab

token-group/js/test/instruction.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import type { Decoder } from '@solana/codecs';
3-
import { fixDecoderSize, getBytesDecoder, getStructDecoder, getU32Decoder } from '@solana/codecs';
3+
import { fixDecoderSize, getBytesDecoder, getStructDecoder, getU64Decoder } from '@solana/codecs';
44
import { splDiscriminate } from '@solana/spl-type-length-value';
55
import { PublicKey, type TransactionInstruction } from '@solana/web3.js';
66

@@ -28,7 +28,7 @@ describe('Token Group Instructions', () => {
2828
const updateAuthority = new PublicKey('44444444444444444444444444444444444444444444');
2929
const mint = new PublicKey('55555555555555555555555555555555555555555555');
3030
const mintAuthority = new PublicKey('66666666666666666666666666666666666666666666');
31-
const maxSize = 100;
31+
const maxSize = BigInt(100);
3232

3333
it('Can create InitializeGroup Instruction', () => {
3434
checkPackUnpack(
@@ -43,7 +43,7 @@ describe('Token Group Instructions', () => {
4343
splDiscriminate('spl_token_group_interface:initialize_token_group'),
4444
getStructDecoder([
4545
['updateAuthority', fixDecoderSize(getBytesDecoder(), 32)],
46-
['maxSize', getU32Decoder()],
46+
['maxSize', getU64Decoder()],
4747
]),
4848
{ updateAuthority: Uint8Array.from(updateAuthority.toBuffer()), maxSize },
4949
);
@@ -58,7 +58,7 @@ describe('Token Group Instructions', () => {
5858
maxSize,
5959
}),
6060
splDiscriminate('spl_token_group_interface:update_group_max_size'),
61-
getStructDecoder([['maxSize', getU32Decoder()]]),
61+
getStructDecoder([['maxSize', getU64Decoder()]]),
6262
{ maxSize },
6363
);
6464
});

0 commit comments

Comments
 (0)