> ## 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.

# 시간 및 Sysvars

> 시간과 시스템 변수를 조작하는 메서드

## 시간 조작

### warp_to_slot

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

특정 slot으로 이동합니다. 이 메서드는 `Clock.slot`만 업데이트하며, epoch와
`unix_timestamp`는 변경되지 않습니다. 앞으로 워프하는 것이 의도된 사용 방식이지만,
뒤로 워프하는 것도 거부되지는 않습니다.

```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);
```

### 수동 Clock 조작

```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>
  대부분의 시간 조작에는 `warp_to_slot()`을 사용하세요. 여러 필드를 정밀하게 제어해야 할 때만
  Clock을 수동으로 수정하세요.
</Info>

## Sysvars

### get_sysvar

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

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>,
```

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

### 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);
```

## 시간 기반 테스트 패턴

### slot 기반 기능 테스트

```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());
```

### 타임스탬프 기반 기능 테스트

```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);
```

### 베스팅 스케줄 테스트

```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());
```

## 주요 사용 사례

- 베스팅 스케줄
- 시간 잠금 출금
- 스테이크/언스테이크 쿨다운 기간
- 경매 종료 시간
- 대여 기간
- epoch 기반 보상

## 중요 참고 사항

1. **앞으로만 이동** - 관례상 앞으로만 워프하세요. LiteSVM은 뒤로 워프하는 것을
   거부하지 않지만, 시간에 의존하는 프로그램이 예기치 않게 동작할 수 있습니다
2. **slot과 시간** - Mainnet의 slot 목표 시간은 200ms(0.2초)이며, 실제 관측되는
   slot은 이보다 약간 더 깁니다. LiteSVM은 slot을 실제 시간(wall-clock time)과 연동하지 않습니다
3. **Clock sysvar** - `warp_to_slot()`은 `slot` 필드만 업데이트합니다. 프로그램이
   `unix_timestamp`와 `epoch`를 읽는 경우, `set_sysvar`로 직접 설정하세요
4. **자동 업데이트 없음** - 실제 validator와 달리, 트랜잭션 사이에 시간이
   자동으로 진행되지 않습니다
