솔라나 문서LiteSVMTypeScriptAPI 레퍼런스

시간 및 Sysvar

시간 조작 및 시스템 변수 접근을 위한 메서드입니다.

sysvar 메서드에 접근하기 전에 먼저 client.svm.withSysvars()를 사용하여 sysvar를 활성화하세요.

클록 조작

warpToSlot

warpToSlot(slot: bigint): LiteSVM

클록을 특정 slot으로 이동합니다.

client.svm.withSysvars();
// Check current slot
const before = client.svm.getClock();
console.log("Current slot:", before.slot);
// Warp forward
client.svm.warpToSlot(10000n);
const after = client.svm.getClock();
console.log("New slot:", after.slot);

getClock

getClock(): Clock

현재 클록 sysvar 값을 가져옵니다.

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

setClock(clock: Clock): LiteSVM

클록 sysvar를 덮어씁니다. 클록을 가져와 필드를 수정한 후 다시 저장합니다. 여러 클록 필드를 정밀하게 제어해야 할 때 사용하세요 — 예를 들어, warpToSlot로는 업데이트되지 않는 epoch 또는 유닉스 타임스탬프를 설정할 때 유용합니다.

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

warpToSlotslot만 업데이트합니다. 프로그램이 Clock sysvar에서 epoch 또는 unix_timestamp를 읽는 경우 setClock를 사용하세요.

클록 속성

속성타입설명
slotbigint현재 slot 번호
epochbigint현재 epoch 번호
unixTimestampbigint초 단위 유닉스 타임스탬프
epochStartTimestampbigint현재 epoch 시작
leaderScheduleEpochbigint리더 스케줄 epoch

Rent

getRent

getRent(): Rent

rent sysvar를 가져옵니다.

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

minimumBalanceForRentExemption(dataLen: bigint): bigint

rent 면제에 필요한 최소 lamport를 계산합니다.

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

getEpochSchedule(): EpochSchedule

epoch 스케줄 sysvar를 가져옵니다.

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

getEpochRewards(): EpochRewards

epoch 보상 sysvar를 가져옵니다.

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

getSlotHashes(): SlotHash[]

최근 slot 해시를 가져옵니다.

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

getSlotHistory(): SlotHistory

slot 기록을 가져옵니다.

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

getLastRestartSlot / setLastRestartSlot

getLastRestartSlot(): bigint
setLastRestartSlot(slot: bigint): LiteSVM

마지막 재시작 slot을 가져오거나 설정합니다.

const lastRestart = client.svm.getLastRestartSlot();
console.log("Last restart slot:", lastRestart);
client.svm.setLastRestartSlot(500n);

스테이크 기록

getStakeHistory

getStakeHistory(): StakeHistory

스테이크 기록을 가져옵니다.

const stakeHistory = client.svm.getStakeHistory();
// Returns array of { epoch, entry: { effective, activating, deactivating } }

시간 의존적 로직 테스트

warpToSlot를 사용하여 시간 의존적 프로그램 동작을 테스트합니다:

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());
client.svm.withSysvars();
const unlockSlot = 10000n;
// 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 ...
}

Is this page helpful?