Quickstart
Clone, deploy to devnet, register a Pyth Lazer feed, delegate a position to MagicBlock ER, fire a 1ms-cadence trigger. Windows native or WSL.
anchor test or npm run dev.Prerequisites
- Rust via rustup
- Solana CLI
- Anchor
- Node 20+ and npm
- A Solana devnet wallet with ~5 SOL (web faucet if rate-limited)
1. Clone & build
git clone https://github.com/Hwaldev/hwal.git
cd hwal
anchor buildFirst build syncs the program ID. The artifact lands attarget/deploy/hwal.so (~322 KB) and the IDL at target/idl/hwal.json.
2. Deploy to devnet
solana config set --url https://api.devnet.solana.com
solana airdrop 5
anchor deploy --provider.cluster devnetBurns ~2.24 SOL of rent for the program account. The deploy signature prints when it lands.
3. Bootstrap config + Lazer feed
This creates the Config PDA and registers a Pyth Lazer feed for SOL/USD on the chosen channel (1ms / 50ms / 200ms). The Lazer feed id is verified at everytick_position call via attestation.
npm install
$env:ANCHOR_PROVIDER_URL = "https://api.devnet.solana.com"
$env:ANCHOR_WALLET = "C:\Users\baayo\.config\solana\id.json"
npx ts-node scripts/setup-devnet.ts --lazer-channel 50ms --feed sol-usd4. Delegate position to MagicBlock ER
Opening a position automatically delegates the PDA to the MagicBlock ephemeral rollup. The position state lives in the ER, ticks at 50ms cadence, and commits back to L1 on trigger fire or cancel.
npx ts-node scripts/smoke-test.ts --delegate-erExpected output
==> position delegated to MagicBlock ER (slot cadence: 50ms)
==> lazer attestation @ 150.000000 → tick (no trigger, tick_count = 1)
==> lazer attestation @ 160.000000 → tick (take-profit fires inside ER)
==> ER state committed to L1 atomically
==> status = 1 (TRIGGERED), trigger_reason = 2 (take-profit)
==> settlement:
trader: +0.049625 SOL (collateral - 0.5% fee - 0.25% keeper)
keeper: +0.000125 SOL (0.05 * 0.25%)
fee_rx: +0.00024 SOL (0.05 * 0.5%, net of tx fee)
==> smoke test PASSED on devnet + ER.5. Run the keeper bot inside ER
npx ts-node scripts/keeper-bot.ts --er --channel 50msSubscribes to the Lazer feed at the chosen channel and submits tick_positioninside the MagicBlock ER for every open position. On a trigger fire, earns 0.25% of the collateral plus the L1 commit reward.
What next
- Read Trigger evaluation for the math.
- Read Latency budget for the 1ms / 50ms / L1 breakdown.
- Skim Instructions for the full ABI.