Skip to content

antoncoding/squeeth-vol-oracle

Repository files navigation

Squeeth Vol Oracle

squeeth

Built with foundry template

Deployments

The contract is deployed on Goerli and Mainnet:

Chain Address
Mainnet 0x5caec004f1378fbfd54a11e9f00e2aad32796b33
Goerli 0x5caec004f1378fbfd54a11e9f00e2aad32796b33

Using the contract

You can use cast to directly query the value as follow (mainnet rpc example):

cast call 0x5caec004f1378fbfd54a11e9f00e2aad32796b33  "getEthTwaIV(uint32)(uint256)" 120 --rpc-url https://rpc.ankr.com/eth

Development

Getting Started

Compile and run tests

forge build

forge test

Estimation

You can clone the contract, tune in a bit and use the following script to estimate real world vol value.

forge script scripts/Deploy.sol --fork-url <mainnet rpc>

Output:

== Logs ==
  implied volatility: 959347350657613352
  gas cost:           97612
  implied funding:    2521499559489813

Gas Cost

The gas cost is around 46K ~ 140K, depends on:

  • secondsAgo to calculate twap
  • current state of Uniswap pool, how many records are in the last secondsAgo seconds

It costs least (around 46K) while querying the implied vol by the current spot price.

Contract Interface

/// @dev return implied vol with 18 decimals (1e18 = 100%)
function getEthTwaIV(uint256 secondsAgo) external view returns (uint256 vol);

/// @dev return daily implied funding with 18 decimals (1e18 = 100%)
function getImpliedFunding(uint32 secondsAgo) external view returns (uint256 impliedFunding);