Skip to content

Commit 7fd78dc

Browse files
authored
refactor(sdk-coin-sol): address code review feedback on constants and offsets
1 parent 0daf8de commit 7fd78dc

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

modules/sdk-coin-sol/src/lib/confidentialMintBuilder.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseCoin as CoinConfig } from '@bitgo/statics';
22
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core';
33
import { Transaction } from './transaction';
44
import { TransactionBuilder } from './transactionBuilder';
5-
import { InstructionBuilderTypes } from './constants';
5+
import { INSTRUCTIONS_SYSVAR_ADDRESS, InstructionBuilderTypes } from './constants';
66
import {
77
ConfidentialMint,
88
ConfigureConfidentialTransferAccount,
@@ -184,8 +184,7 @@ export class ConfidentialMintBuilder extends TransactionBuilder {
184184
mintAddress: this._configureParams.mintAddress,
185185
authorityAddress: this._configureParams.authorityAddress,
186186
instructionsSysvarOrContextStateAddress:
187-
this._configureParams.instructionsSysvarOrContextStateAddress ||
188-
'Sysvar1nstructions1111111111111111111111111',
187+
this._configureParams.instructionsSysvarOrContextStateAddress || INSTRUCTIONS_SYSVAR_ADDRESS,
189188
decryptableZeroBalance: this._configureParams.decryptableZeroBalance,
190189
maximumPendingBalanceCreditCounter: this._configureParams.maximumPendingBalanceCreditCounter,
191190
proofInstructionOffset: this._configureParams.proofInstructionOffset ?? 0,
@@ -196,7 +195,7 @@ export class ConfidentialMintBuilder extends TransactionBuilder {
196195
if (this._mintParams) {
197196
const params = this._mintParams;
198197
const recordOwner = params.recordAccountOwnerAddress || params.contextStateAuthorityAddress;
199-
const space = Math.ceil(Buffer.from(params.rangeRecordData, 'hex').length / 2) * 2;
198+
const space = Buffer.from(params.rangeRecordData, 'hex').length;
200199

201200
instructions.push({
202201
type: InstructionBuilderTypes.CreateRecordAccount,

modules/sdk-coin-sol/src/lib/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export const JITO_STAKE_POOL_RESERVE_ACCOUNT_TESTNET = 'rrWBQqRqBXYZw3CmPCCcjFxQ
3535
export const JITO_MANAGER_FEE_ACCOUNT = 'feeeFLLsam6xZJFc6UQFrHqkvVt4jfmVvi2BRLkUZ4i';
3636
export const JITO_MANAGER_FEE_ACCOUNT_TESTNET = 'DH7tmjoQ5zjqcgfYJU22JqmXhP5EY1tkbYpgVWUS2oNo';
3737

38+
/** Solana Instructions sysvar address. Used by Token-2022 extension instructions that verify proofs in-tx. */
39+
export const INSTRUCTIONS_SYSVAR_ADDRESS = 'Sysvar1nstructions1111111111111111111111111';
40+
3841
// Sdk instructions, mainly to check decoded types.
3942
export enum ValidInstructionTypesEnum {
4043
AdvanceNonceAccount = 'AdvanceNonceAccount',

modules/sdk-coin-sol/src/lib/solInstructionFactory.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import assert from 'assert';
2828
import BigNumber from 'bignumber.js';
2929
import { struct, u8, blob } from '@solana/buffer-layout';
30-
import { InstructionBuilderTypes, MEMO_PROGRAM_PK } from './constants';
30+
import { INSTRUCTIONS_SYSVAR_ADDRESS, InstructionBuilderTypes, MEMO_PROGRAM_PK } from './constants';
3131
import {
3232
AtaClose,
3333
AtaInit,
@@ -850,7 +850,7 @@ function configureConfidentialTransferAccountInstruction(
850850
{ pubkey: new PublicKey(tokenAddress), isSigner: false, isWritable: true },
851851
{ pubkey: new PublicKey(mintAddress), isSigner: false, isWritable: false },
852852
{
853-
pubkey: new PublicKey(instructionsSysvarOrContextStateAddress || 'Sysvar1nstructions1111111111111111111111111'),
853+
pubkey: new PublicKey(instructionsSysvarOrContextStateAddress || INSTRUCTIONS_SYSVAR_ADDRESS),
854854
isSigner: false,
855855
isWritable: false,
856856
},
@@ -1004,6 +1004,8 @@ function writeRecordDataInstruction(data: WriteRecordData): TransactionInstructi
10041004
assert(recordData, 'Missing data param');
10051005

10061006
const dataBuffer = Buffer.from(recordData, 'hex');
1007+
const offsetBuffer = Buffer.alloc(4);
1008+
offsetBuffer.writeUInt32LE(offset, 0);
10071009
return [
10081010
new TransactionInstruction({
10091011
keys: [
@@ -1013,7 +1015,7 @@ function writeRecordDataInstruction(data: WriteRecordData): TransactionInstructi
10131015
: []),
10141016
],
10151017
programId: new PublicKey(recordAccountOwnerAddress || ZK_ELGAMAL_PROOF_PROGRAM_ID),
1016-
data: Buffer.concat([Buffer.from([1]), Buffer.from(new Uint32Array([offset]).buffer), dataBuffer]),
1018+
data: Buffer.concat([Buffer.from([1]), offsetBuffer, dataBuffer]),
10171019
}),
10181020
];
10191021
}

0 commit comments

Comments
 (0)