Testing & Debugging
Forked Mainnet with Anvil
The recommended way to test Varla integrations is by forking Polygon mainnet using Foundry's Anvil. This gives you a local environment with real contract state, real Polymarket positions, and real oracle data — far more realistic than any testnet.
ℹ Why forked mainnet?
Forking mainnet means you're testing against real deployed contracts with real state. No test tokens, no synthetic data, no guessing whether testnet behavior matches production. What works on your fork will work on mainnet.
Start a forked mainnet bash
# Fork Polygon mainnet with Anvil
anvil --fork-url https://polygon-rpc.com --fork-block-number latest
# Your local RPC is now available at http://127.0.0.1:8545
# All mainnet contracts and state are available locally Testing Workflow
1
Fork mainnet
Use Foundry's
anvil --fork-url to create a local fork of Polygon mainnet. This gives you a realistic environment with real contract state.
2
Impersonate accounts
Use
anvil_impersonateAccount to act as any address — useful for testing with real Polymarket positions without owning them.
3
Time travel
Use
evm_increaseTime to simulate interest accrual, oracle staleness, and early-closure decay without waiting.
4
Test edge cases
Manipulate oracle prices, simulate liquidation scenarios, and test bad debt handling in a controlled environment.
Common Issues
Debugging checklist
Transaction reverted?
├── Check: Is oracle fresh? (isFresh() returns false → wait for update)
├── Check: Is health factor sufficient? (post-action HF must be ≥ 1.0)
├── Check: Is pool liquid? (enough available stablecoins for borrow)
├── Check: Is ERC-1155 approved? (setApprovalForAll must be called first)
└── Check: Is position eligible? (oracle must have active feed for tokenId)
Unexpected values?
├── Interest is per-second → debt grows between reads
├── Oracle uses min(spot, TWAP) → may be lower than expected
└── Early-closure decay → LTV drops near resolution 💡 SDK debugging
The SDK includes a
debug: true option that logs all contract calls, parameters, and return values. Enable it during development.