> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Tiempo y Sysvars

> Métodos para manipular el tiempo y las variables del sistema

## Manipulación del tiempo

### warp_to_slot

```rust
pub fn warp_to_slot(&mut self, slot: u64)
```

Salta a un slot específico. Esto actualiza únicamente `Clock.slot`; el epoch y
`unix_timestamp` permanecen sin cambios. Avanzar es el uso previsto, pero los
saltos hacia atrás no se rechazan.

```rust
// Get current slot
let clock: Clock = svm.get_sysvar();
let current_slot = clock.slot;

// Jump forward 100 slots
svm.warp_to_slot(current_slot + 100);

// Verify
let new_clock: Clock = svm.get_sysvar();
assert_eq!(new_clock.slot, current_slot + 100);
```

### Manipulación manual del reloj

```rust
use solana_sdk::clock::Clock;

// Read clock
let mut clock: Clock = svm.get_sysvar();

// Modify fields
clock.slot = 1000;
clock.epoch = 10;
clock.unix_timestamp = 1735689600;

// Write back
svm.set_sysvar(&clock);
```

<Info>
  Usa `warp_to_slot()` para la mayoría de las manipulaciones de tiempo. Usa la modificación manual del reloj
  solo cuando necesites un control preciso sobre varios campos.
</Info>

## Sysvars

### get_sysvar

```rust
pub fn get_sysvar<T>(&self) -> T
where
    T: Sysvar + SysvarId + DeserializeOwned<Dst = T>,
```

Lee el valor de un sysvar.

```rust
use solana_sdk::clock::Clock;
use solana_sdk::rent::Rent;
use solana_sdk::epoch_schedule::EpochSchedule;

let clock: Clock = svm.get_sysvar();
let rent: Rent = svm.get_sysvar();
let epoch_schedule: EpochSchedule = svm.get_sysvar();
```

### set_sysvar

```rust
pub fn set_sysvar<T>(&mut self, sysvar: &T)
where
    T: Sysvar + SysvarId + Serialize<Src = T>,
```

Escribe el valor de un sysvar.

```rust
use solana_sdk::rent::Rent;

// Read the current rent, change a field, and write it back
let mut rent: Rent = svm.get_sysvar();
rent.lamports_per_byte = 3480;

svm.set_sysvar(&rent);
```

## Sysvars comunes

### Clock

```rust
use solana_sdk::clock::Clock;

let clock: Clock = svm.get_sysvar();
println!("Slot: {}", clock.slot);
println!("Timestamp: {}", clock.unix_timestamp);
println!("Epoch: {}", clock.epoch);
```

### Rent

```rust
use solana_sdk::rent::Rent;

let rent: Rent = svm.get_sysvar();
let min_balance = rent.minimum_balance(data_len);
```

### Epoch Schedule

```rust
use solana_sdk::epoch_schedule::EpochSchedule;

let schedule: EpochSchedule = svm.get_sysvar();
println!("Slots per epoch: {}", schedule.slots_per_epoch);
```

### Stake History

```rust
// cargo add --dev solana-sysvar@4.2
use solana_sysvar::stake_history::{StakeHistory, StakeHistoryEntry};

let mut stake_history = StakeHistory::default();
stake_history.add(
    0, // epoch
    StakeHistoryEntry {
        effective: 1_000_000,
        activating: 0,
        deactivating: 0,
    },
);

svm.set_sysvar(&stake_history);
```

## Patrones de pruebas basadas en el tiempo

### Probar funciones basadas en slots

```rust
let mut svm = LiteSVM::new();

// Get starting slot
let start_slot = svm.get_sysvar::<Clock>().slot;

// Try action before unlock slot (should fail)
let result = call_locked_program(&mut svm);
assert!(result.is_err());

// Warp to unlock slot
svm.warp_to_slot(start_slot + 1000);

// Now it should succeed
let result = call_locked_program(&mut svm);
assert!(result.is_ok());
```

### Probar funciones basadas en marcas de tiempo

```rust
let mut svm = LiteSVM::new();

// Get current timestamp
let clock: Clock = svm.get_sysvar();
let current_time = clock.unix_timestamp;

// Warp forward 1 hour (3600 seconds)
// Mainnet slots target 200ms (0.2 seconds)
let target_slot = clock.slot + (3600.0 / 0.2) as u64;
// `warp_to_slot` only moves the slot, so set the timestamp yourself
let mut warped: Clock = svm.get_sysvar();
warped.slot = target_slot;
warped.unix_timestamp = current_time + 3600;
svm.set_sysvar(&warped);

// Verify timestamp increased
let new_clock: Clock = svm.get_sysvar();
assert!(new_clock.unix_timestamp >= current_time + 3600);
```

### Probar calendarios de vesting

```rust
// Setup vesting with 100 slot period
let vesting_period = 100;
let start_slot = svm.get_sysvar::<Clock>().slot;

// Test before vesting completes
let result = claim_vested_tokens(&mut svm);
assert!(result.is_err()); // Too early

// Warp past vesting period
svm.warp_to_slot(start_slot + vesting_period + 1);

// Now claim should succeed
let result = claim_vested_tokens(&mut svm);
assert!(result.is_ok());
```

## Casos de uso comunes

- Calendarios de vesting
- Retiros con bloqueo temporal
- Períodos de enfriamiento de stake/unstake
- Horas de finalización de subastas
- Períodos de alquiler
- Recompensas basadas en epoch

## Notas importantes

1. **Solo hacia adelante** - Avanza por convención. LiteSVM no rechaza un salto
   hacia atrás, pero los programas que dependen del tiempo pueden comportarse de forma inesperada
2. **De slot a tiempo** - Los slots de Mainnet apuntan a 200 ms (0,2 segundos); los slots
   observados duran algo más. LiteSVM no vincula los slots con el tiempo real
3. **Sysvar Clock** - `warp_to_slot()` actualiza solo el campo `slot`. Establece
   `unix_timestamp` y `epoch` tú mismo con `set_sysvar` cuando tu programa
   los lea
4. **Sin actualizaciones automáticas** - A diferencia de los validators reales, el tiempo no avanza
   automáticamente entre transacciones
