Skip to content

Updates the configuration of an existing Settings account. Only the current admin can call this instruction.

pub fn update_settings(
ctx: Context<UpdateSettings>,
range_signer: Option<Pubkey>,
window_size: Option<u64>,
) -> Result<()>
ParameterTypeDescription
range_signerOption<Pubkey>New trusted signer pubkey (optional)
window_sizeOption<u64>New time window in seconds (optional)
AccountTypeDescription
adminSignerCurrent admin of the Settings account
settingsAccount<Settings>Settings PDA to update
import { buildUpdateSettingsInstruction } from './codama-ts-range-custom';
// Update both values
const instruction = await buildUpdateSettingsInstruction({
admin: walletPublicKey,
rangeSigner: newBackendPublicKey,
windowSize: 120n,
});
// Update only window_size
const instruction2 = await buildUpdateSettingsInstruction({
admin: walletPublicKey,
windowSize: 90n,
// rangeSigner not provided - keeps current value
});
// Update only range_signer
const instruction3 = await buildUpdateSettingsInstruction({
admin: walletPublicKey,
rangeSigner: newBackendPublicKey,
// windowSize not provided - keeps current value
});
await program.methods
.updateSettings(
newRangeSigner, // Option<Pubkey>
new BN(120) // Option<u64>
)
.accounts({
admin: wallet.publicKey,
settings: settingsPda,
})
.rpc();
  1. Verifies caller is the current admin
  2. If range_signer provided, updates to new value
  3. If window_size provided, updates to new value
  4. Values not provided remain unchanged
ErrorCause
Constraint violationCaller is not the admin
Account not foundSettings account doesn’t exist

If your backend signing key is compromised or you want to rotate keys:

// Generate new backend keypair
const newRangeSigner = Keypair.generate();
const instruction = await buildUpdateSettingsInstruction({
admin: adminPublicKey,
rangeSigner: newRangeSigner.publicKey,
});
// After transaction confirms, update your backend to use newRangeSigner

If you’re seeing TimestampOutOfWindow errors due to network latency:

const instruction = await buildUpdateSettingsInstruction({
admin: adminPublicKey,
windowSize: 120n, // Increase from 60 to 120 seconds
});

If you suspect key compromise, rotate immediately:

async function emergencyKeyRotation(
admin: Keypair,
connection: Connection
) {
// Generate new keypair
const newRangeSigner = Keypair.generate();
const instruction = await buildUpdateSettingsInstruction({
admin: admin.publicKey,
rangeSigner: newRangeSigner.publicKey,
});
// Use high priority for fast confirmation
const transaction = new Transaction().add(instruction);
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
transaction.feePayer = admin.publicKey;
transaction.sign(admin);
const signature = await connection.sendRawTransaction(
transaction.serialize(),
{ skipPreflight: false }
);
console.log('Key rotated:', signature);
console.log('New range_signer:', newRangeSigner.publicKey.toBase58());
// IMPORTANT: Immediately update backend with new keypair
return newRangeSigner;
}