1212 program_error:: { ProgramError , ToStr } ,
1313 ProgramResult , MAX_TX_ACCOUNTS , SUCCESS ,
1414 } ,
15- pinocchio_token_interface:: { error:: TokenError , likely} ,
15+ pinocchio_token_interface:: {
16+ error:: TokenError ,
17+ instruction:: TokenInstruction ,
18+ likely,
19+ state:: { account:: Account , mint:: Mint , Transmutable } ,
20+ } ,
1621} ;
1722
1823// Do not allocate memory.
@@ -65,15 +70,15 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
6570 /// length.
6671 const IX12_ACCOUNT4_DATA_LEN : usize = 0x7b20 ;
6772
68- /// Expected offset for the instruction data in the case all
69- /// previous accounts have zero data.
73+ /// Expected offset for the instruction data in the case the
74+ /// fourth (authority) account has zero data.
7075 ///
7176 /// This value is adjusted before it is used.
7277 const IX12_EXPECTED_INSTRUCTION_DATA_LEN_OFFSET : usize = 0xa330 ;
7378
7479 // Constants that apply to `transfer` (instruction 3).
7580
76- /// Offset for the second account.
81+ /// Offset for the third account.
7782 ///
7883 /// Note that this assumes that both first and second accounts
7984 /// have zero data, which is being validated before the offset
@@ -84,8 +89,8 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
8489 /// expected to be a mint account (82 bytes).
8590 const IX3_ACCOUNT3_DATA_LEN : usize = 0x5268 ;
8691
87- /// Expected offset for the instruction data in the case all
88- /// previous accounts have zero data.
92+ /// Expected offset for the instruction data in the case the
93+ /// third (authority) account has zero data.
8994 ///
9095 /// This value is adjusted before it is used.
9196 const IX3_INSTRUCTION_DATA_LEN_OFFSET : usize = 0x7a78 ;
@@ -107,11 +112,11 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
107112 // Instruction data is expected to be at least 9 bytes
108113 // and discriminator equal to 12.
109114 if * input == 4
110- && ( * input. add ( ACCOUNT1_DATA_LEN ) . cast :: < u64 > ( ) == 165 )
115+ && ( * input. add ( ACCOUNT1_DATA_LEN ) . cast :: < u64 > ( ) == Account :: LEN as u64 )
111116 && ( * input. add ( ACCOUNT2_HEADER_OFFSET ) == 255 )
112- && ( * input. add ( ACCOUNT2_DATA_LEN ) . cast :: < u64 > ( ) == 82 )
117+ && ( * input. add ( ACCOUNT2_DATA_LEN ) . cast :: < u64 > ( ) == Mint :: LEN as u64 )
113118 && ( * input. add ( IX12_ACCOUNT3_HEADER_OFFSET ) == 255 )
114- && ( * input. add ( IX12_ACCOUNT3_DATA_LEN ) . cast :: < u64 > ( ) == 165 )
119+ && ( * input. add ( IX12_ACCOUNT3_DATA_LEN ) . cast :: < u64 > ( ) == Account :: LEN as u64 )
115120 && ( * input. add ( IX12_ACCOUNT4_HEADER_OFFSET ) == 255 )
116121 {
117122 // The `authority` account can have variable data length.
@@ -122,11 +127,11 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
122127 // Check that we have enough instruction data.
123128 //
124129 // Expected: instruction discriminator (u8) + amount (u64) + decimals (u8)
125- if input. add ( offset) . cast :: < usize > ( ) . read ( ) >= 10 {
130+ if input. add ( offset) . cast :: < u64 > ( ) . read ( ) >= 10 {
126131 let discriminator = input. add ( offset + size_of :: < u64 > ( ) ) . cast :: < u8 > ( ) . read ( ) ;
127132
128133 // Check for transfer discriminator.
129- if likely ( discriminator == 12 ) {
134+ if likely ( discriminator == TokenInstruction :: TransferChecked as u8 ) {
130135 // instruction data length (u64) + discriminator (u8)
131136 let instruction_data = unsafe { from_raw_parts ( input. add ( offset + 9 ) , 9 ) } ;
132137
@@ -162,9 +167,9 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
162167 // Instruction data is expected to be at least 8 bytes
163168 // and discriminator equal to 3.
164169 else if * input == 3
165- && ( * input. add ( ACCOUNT1_DATA_LEN ) . cast :: < u64 > ( ) == 165 )
170+ && ( * input. add ( ACCOUNT1_DATA_LEN ) . cast :: < u64 > ( ) == Account :: LEN as u64 )
166171 && ( * input. add ( ACCOUNT2_HEADER_OFFSET ) == 255 )
167- && ( * input. add ( ACCOUNT2_DATA_LEN ) . cast :: < u64 > ( ) == 165 )
172+ && ( * input. add ( ACCOUNT2_DATA_LEN ) . cast :: < u64 > ( ) == Account :: LEN as u64 )
168173 && ( * input. add ( IX3_ACCOUNT3_HEADER_OFFSET ) == 255 )
169174 {
170175 // The `authority` account can have variable data length.
@@ -173,11 +178,11 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
173178 let offset = IX3_INSTRUCTION_DATA_LEN_OFFSET + account_3_data_len_aligned;
174179
175180 // Check that we have enough instruction data.
176- if likely ( input. add ( offset) . cast :: < usize > ( ) . read ( ) >= 9 ) {
181+ if likely ( input. add ( offset) . cast :: < u64 > ( ) . read ( ) >= 9 ) {
177182 let discriminator = input. add ( offset + size_of :: < u64 > ( ) ) . cast :: < u8 > ( ) . read ( ) ;
178183
179184 // Check for transfer discriminator.
180- if likely ( discriminator == 3 ) {
185+ if likely ( discriminator == TokenInstruction :: Transfer as u8 ) {
181186 let instruction_data =
182187 unsafe { from_raw_parts ( input. add ( offset + 9 ) , size_of :: < u64 > ( ) ) } ;
183188
0 commit comments