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

> التحكم بالساعة والوصول إلى Sysvars في TypeScript

طرق للتحكم في الوقت والوصول إلى متغيرات النظام.

## التحكم في الساعة

### warpToSlot

```typescript
warpToSlot(slot: bigint): void
```

تقديم الساعة إلى slot محدد.

```typescript
// Check current slot
const before = client.svm.getClock();
console.log("Current slot:", before.slot);

// Warp forward 10,000 slots
client.svm.warpToSlot(before.slot + 10_000n);

const after = client.svm.getClock();
console.log("New slot:", after.slot);
```

### getClock

```typescript
getClock(): Clock
```

الحصول على قيم Clock sysvar الحالية.

```typescript
const clock = client.svm.getClock();

console.log("Slot:", clock.slot);
console.log("Epoch:", clock.epoch);
console.log("Unix timestamp:", clock.unixTimestamp);
console.log("Epoch start timestamp:", clock.epochStartTimestamp);
console.log("Leader schedule epoch:", clock.leaderScheduleEpoch);
```

### setClock

```typescript
setClock(clock: Clock): void
```

استبدال قيم Clock sysvar. احصل على الساعة، ثم عدّل حقولها، ثم اكتبها مجددًا. استخدم هذا عندما تحتاج إلى تحكم دقيق في عدة حقول للساعة — على سبيل المثال، تعيين epoch أو الطابع الزمني بنظام Unix، وهو ما لا تقوم `warpToSlot` بتحديثه.

```typescript
const clock = client.svm.getClock();
clock.slot = 1000n;
clock.epoch = 10n;
clock.unixTimestamp = 1735689600n;
client.svm.setClock(clock);
```

<Info>
  تقوم `warpToSlot` بتحديث `slot` فقط. استخدم `setClock` عندما يقرأ برنامجك `epoch` أو `unix_timestamp` من Clock sysvar.
</Info>

### خصائص الساعة

| الخاصية              | النوع     | الوصف               |
| --------------------- | -------- | ------------------------- |
| `slot`                | `bigint` | رقم slot الحالي       |
| `epoch`               | `bigint` | رقم epoch الحالي      |
| `unixTimestamp`       | `bigint` | الطابع الزمني بنظام Unix بالثواني |
| `epochStartTimestamp` | `bigint` | بداية epoch الحالي    |
| `leaderScheduleEpoch` | `bigint` | epoch جدول القادة     |

## Rent

### getRent

```typescript
getRent(): Rent
```

الحصول على Rent sysvar.

```typescript
const rent = client.svm.getRent();

console.log("Lamports per byte-year:", rent.lamportsPerByteYear);
console.log("Exemption threshold:", rent.exemptionThreshold);
console.log("Burn percent:", rent.burnPercent);
```

### minimumBalanceForRentExemption

```typescript
minimumBalanceForRentExemption(dataLen: bigint): bigint
```

حساب الحد الأدنى من lamports اللازم للإعفاء من rent.

```typescript
// Calculate for different data sizes
for (const size of [0n, 100n, 1000n]) {
  const min = client.svm.minimumBalanceForRentExemption(size);
  console.log(`${size} bytes: ${min} lamports`);
}
```

## جدول epoch

### getEpochSchedule

```typescript
getEpochSchedule(): EpochSchedule
```

الحصول على sysvar الخاص بجدول epoch.

```typescript
const epochSchedule = client.svm.getEpochSchedule();

console.log("Slots per epoch:", epochSchedule.slotsPerEpoch);
console.log(
  "Leader schedule slot offset:",
  epochSchedule.leaderScheduleSlotOffset
);
console.log("Warmup:", epochSchedule.warmup);
console.log("First normal epoch:", epochSchedule.firstNormalEpoch);
console.log("First normal slot:", epochSchedule.firstNormalSlot);
```

## مكافآت epoch

### getEpochRewards

```typescript
getEpochRewards(): EpochRewards
```

الحصول على sysvar الخاص بمكافآت epoch.

```typescript
const rewards = client.svm.getEpochRewards();

console.log("Active:", rewards.active);
console.log("Total rewards:", rewards.totalRewards);
console.log("Distributed rewards:", rewards.distributedRewards);
console.log("Total points:", rewards.totalPoints);
console.log("Num partitions:", rewards.numPartitions);
console.log(
  "Distribution starting block height:",
  rewards.distributionStartingBlockHeight
);
```

## معلومات slot

### getSlotHashes

```typescript
getSlotHashes(): SlotHash[]
```

الحصول على تجزئات slot الأخيرة.

```typescript
const slotHashes = client.svm.getSlotHashes();

console.log("Slot hashes count:", slotHashes.length);
if (slotHashes.length > 0) {
  console.log("First hash:", {
    slot: slotHashes[0].slot,
    hash: slotHashes[0].hash
  });
}
```

### getSlotHistory

```typescript
getSlotHistory(): SlotHistory
```

الحصول على سجل slot.

```typescript
const slotHistory = client.svm.getSlotHistory();
console.log("Next slot:", slotHistory.nextSlot);
```

### getLastRestartSlot / setLastRestartSlot

```typescript
getLastRestartSlot(): bigint
setLastRestartSlot(slot: bigint): void
```

الحصول على آخر slot لإعادة التشغيل أو تعيينه.

```typescript
const lastRestart = client.svm.getLastRestartSlot();
console.log("Last restart slot:", lastRestart);

client.svm.setLastRestartSlot(500n);
```

## سجل الستيكنغ

### getStakeHistory

```typescript
getStakeHistory(): StakeHistory
```

الحصول على سجل الستيكنغ.

```typescript
const stakeHistory = client.svm.getStakeHistory();
// Returns the StakeHistory sysvar (not a plain array)
```

## اختبار المنطق المعتمد على الوقت

استخدم `warpToSlot` لاختبار سلوك البرنامج المعتمد على الوقت:

```typescript
import { createClient, generateKeyPairSigner } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";

async function testTimeLockedVault() {
  const mySigner = await generateKeyPairSigner();
  const client = createClient().use(signer(mySigner)).use(litesvm());

  // LiteSVM starts at a recent mainnet slot, so set the unlock relative to it
  const unlockSlot = client.svm.getClock().slot + 10_000n;

  // Setup: Create time-locked account
  // ... set up your account state ...

  // Test 1: Try to withdraw before unlock (should fail)
  const beforeClock = client.svm.getClock();
  console.log("Current slot:", beforeClock.slot);
  // ... attempt withdrawal, expect failure ...

  // Warp time forward past unlock slot
  client.svm.warpToSlot(unlockSlot + 1n);

  // Test 2: Try to withdraw after unlock (should succeed)
  const afterClock = client.svm.getClock();
  console.log("New slot:", afterClock.slot);
  // ... attempt withdrawal, expect success ...
}
```
