Skip to content

Instantly share code, notes, and snippets.

@rayeaster
Last active October 11, 2022 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayeaster/db6874f2f3faad047ee25160e6288049 to your computer and use it in GitHub Desktop.
Save rayeaster/db6874f2f3faad047ee25160e6288049 to your computer and use it in GitHub Desktop.
PRICER-TWAP
const hre = require("hardhat");
require("@nomiclabs/hardhat-ethers");
const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
const vusd = "0x677ddbd918637E5F2c79e164D402454dE7dA8619"
const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const uniswap_v3_usdc_eth_5 = '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640';
const uniswap_v3_usdc_vusd_5 = '0x8dDE0A1481b4A14bC1015A5a8b260ef059E9FD89';
const eth_deployer = "0xE78388b4CE79068e89Bf8aA7f218eF6b9AB0e9d0";
describe("pricer-twap", function () {
it("Should read twap from pricer", async function () {
this.timeout(1000000);
await hre.network.provider.request({method: "hardhat_impersonateAccount", params: [eth_deployer]});
const txSigner = await ethers.provider.getSigner(eth_deployer);
let blockNumber = await ethers.provider.getBlockNumber();
const univ3Sim = await ethers.getContractFactory("UniV3SwapSimulator");
const univ3Simulator = await univ3Sim.connect(txSigner).deploy();
const balancerSim = await ethers.getContractFactory("BalancerSwapSimulator");
const balancerSimulator = await balancerSim.connect(txSigner).deploy();
const pricerLenient = await ethers.getContractFactory("OnChainPricingMainnetLenient");
const pricer = await pricerLenient.connect(txSigner).deploy(univ3Simulator.address, balancerSimulator.address);
// https://uniswap.org/whitepaper-v3.pdf
let poolSpacing = 10;
// around 10 minutes
let oracleAgo = 50 * 12;
let observeDuration = [oracleAgo, 0];
const vusdPool = await ethers.getContractAt("contracts/OnChainPricerV3.sol:IUniswapV3Pool", uniswap_v3_usdc_vusd_5);
let vusdObservations = await vusdPool.observe(observeDuration);
let vusdObservedTick0 = ethers.utils.parseUnits(vusdObservations[0][0].toString(), 0);
let vusdObservedTick1 = ethers.utils.parseUnits(vusdObservations[0][1].toString(), 0);
let vusdTwapTick = (vusdObservedTick1 - vusdObservedTick0) / oracleAgo;
let vusdAdjustDecimalFactor = 1 / Math.pow(10, Math.abs(6 - 18));
let vusdTwapPrice0To1 = Math.pow(1.0001, vusdTwapTick) / vusdAdjustDecimalFactor;
let vusdSqrtK = ethers.utils.parseUnits((await vusdPool.liquidity()).toString(), 0);
let vusdSlot0 = await vusdPool.slot0();
let vusdTick = ethers.utils.parseUnits(vusdSlot0[1].toString(), 0);
let vusdSqrtTickP = Math.pow(Math.pow(1.0001, vusdTick), 0.5);
let vusdQuotient = Math.floor(vusdTick / poolSpacing);
let vusdTickLower = vusdQuotient * poolSpacing;
let vusdTickUpper = (vusdQuotient + 1) * poolSpacing;
let vusdSqrtTickLowerP = Math.pow(Math.pow(1.0001, vusdTickLower), 0.5);
let vusdSqrtTickUpperP = Math.pow(Math.pow(1.0001, vusdTickUpper), 0.5);
let vusdToken1Res = vusdSqrtK * (vusdSqrtTickP - vusdSqrtTickLowerP);
let vusdToken0Res = vusdSqrtK * (vusdSqrtTickUpperP - vusdSqrtTickP) / (vusdSqrtTickP * vusdSqrtTickUpperP);
let vusdAmt = ethers.utils.parseUnits("10000", 18);
let vusdQuote = ethers.utils.parseUnits((await pricer.findOptimalSwap(vusd, usdc, vusdAmt))[1].toString(), 0);
console.log("current block#=" + blockNumber + ',10000vusd->usdc=' + (vusdQuote.toNumber() / 1e6) + ', vusdRes=' + (vusdToken0Res / 1e18) + ', usdcRes=' + (vusdToken1Res / 1e6) + ', twapVusd2USDC=' + vusdTwapPrice0To1);
const wethPool = await ethers.getContractAt("contracts/OnChainPricerV3.sol:IUniswapV3Pool", uniswap_v3_usdc_eth_5);
let wethObservations = await wethPool.observe(observeDuration);
let wethObservedTick0 = ethers.utils.parseUnits(wethObservations[0][0].toString(), 0);
let wethObservedTick1 = ethers.utils.parseUnits(wethObservations[0][1].toString(), 0);
let wethTwapTick = (wethObservedTick1 - wethObservedTick0) / oracleAgo;
let wethAdjustDecimalFactor = Math.pow(10, Math.abs(6 - 18));
let wethTwapPrice0To1 = Math.pow(1.0001, wethTwapTick) / wethAdjustDecimalFactor;
let wethTwapPrice1To0 = 1 / wethTwapPrice0To1;
let wethSqrtK = ethers.utils.parseUnits((await wethPool.liquidity()).toString(), 0);
//console.log('wethK=' + wethSqrtK);
let wethSlot0 = await wethPool.slot0();
let wethTick = ethers.utils.parseUnits(wethSlot0[1].toString(), 0);
let wethSqrtTickP = Math.pow(Math.pow(1.0001, wethTick), 0.5);
//console.log('wethSqrtTickP=' + wethSqrtTickP + ', wethTick=' + wethTick);
let wethQuotient = Math.floor(wethTick / poolSpacing);
let wethTickLower = wethQuotient * poolSpacing;
let wethTickUpper = (wethQuotient + 1) * poolSpacing;
let wethSqrtTickLowerP = Math.pow(Math.pow(1.0001, wethTickLower), 0.5);
//console.log('wethSqrtTickLowerP=' + wethSqrtTickLowerP + ', wethTickLower=' + wethTickLower + ', wethTickUpper=' + wethTickUpper);
let wethSqrtTickUpperP = Math.pow(Math.pow(1.0001, wethTickUpper), 0.5);
let wethToken1Res = wethSqrtK * (wethSqrtTickP - wethSqrtTickLowerP);
let wethToken0Res = wethSqrtK * (wethSqrtTickUpperP - wethSqrtTickP) / (wethSqrtTickP * wethSqrtTickUpperP);
let wethAmt = ethers.utils.parseUnits("10", 18);
let wethQuote = ethers.utils.parseUnits((await pricer.findOptimalSwap(weth, usdc, wethAmt))[1].toString(), 0);
console.log("current block#=" + blockNumber + ',10weth->usdc=' + (wethQuote.toNumber() / 1e6) + ', usdcRes=' + (wethToken0Res / 1e6) + ', wethRes=' + (wethToken1Res / 1e18) + ', twapWeth2USDC=' + wethTwapPrice1To0);
});
});
package hello.badgerdao;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PricerData {
public static void main(String[] args) {
generatePricerQuotesInUniV3("your-path-to-the-file/vusd-raw-data.csv");
}
private static void generatePricerQuotesInUniV3(String fileName) {
File f = null;
List<String> blocks = new ArrayList<String>();
List<String> vusdQuotes = new ArrayList<String>();
List<String> wethQuotes = new ArrayList<String>();
List<String> vusdLiq0s = new ArrayList<String>();
List<String> vusdLiq1s = new ArrayList<String>();
List<String> wethLiq0s = new ArrayList<String>();
List<String> wethLiq1s = new ArrayList<String>();
List<String> vusdTwaps = new ArrayList<String>();
List<String> wethTwaps = new ArrayList<String>();
int count = 0;
List<String> lines = new ArrayList<String>();
try {
f = new File(fileName);
BufferedReader brdr = new BufferedReader(new FileReader(f));
String blockLine = brdr.readLine();
while(blockLine != null && blockLine.length() > 0) {
lines.add(blockLine);
blockLine = brdr.readLine();
count++;
}
System.out.println("read " + count + " lines of block data in file: " + fileName);
brdr.close();
} catch (Exception e) {
System.out.println("failed to reading file: " + fileName);
}
for(int i = count - 1;i >= 0;i--) {
String blockLine = lines.get(i);
List<String> parsed = parseBlockLineForPricerQuoteInUniV3(blockLine);
if (blockLine.contains("vusd")) {
blocks.add(parsed.get(0));
vusdQuotes.add(String.valueOf(Double.parseDouble(parsed.get(1)) / 10000));
vusdLiq0s.add(parsed.get(2));
vusdLiq1s.add(parsed.get(3));
vusdTwaps.add(parsed.get(4));
} else if(blockLine.contains("weth")) {
wethQuotes.add(String.valueOf(Double.parseDouble(parsed.get(1)) / 10));
wethLiq0s.add(parsed.get(2));
wethLiq1s.add(parsed.get(3));
wethTwaps.add(parsed.get(4));
}
}
//printArraysInOneLine(blocks);
//printArraysInOneLine(vusdQuotes);
//printArraysInOneLine(vusdLiq0s);
//printArraysInOneLine(vusdLiq1s);
//printArraysInOneLine(vusdTwaps);
//printArraysInOneLine(wethQuotes);
//printArraysInOneLine(wethLiq0s);
//printArraysInOneLine(wethLiq1s);
//printArraysInOneLine(wethTwaps);
// 50 blocks is 10 minutes
int windowSize = 50;
// each block is 12 seconds
int interval = 12;
List<String> subBlocks = blocks.subList(windowSize - 1, blocks.size());
printArraysInOneLine(subBlocks);
/////////////////////////////////////////////////////////////////////////////////
// pricer quotes TWAP
/////////////////////////////////////////////////////////////////////////////////
List<String> vusdQuotesTwap = calcTwap(vusdQuotes, interval, windowSize);
//printArraysInOneLine(vusdQuotesTwap);
List<String> subVusdTwaps = vusdTwaps.subList(windowSize - 1, blocks.size());
//printArraysInOneLine(subVusdTwaps);
List<String> wethQuotesTwap = calcTwap(wethQuotes, interval, windowSize);
//printArraysInOneLine(wethQuotesTwap);
List<String> subWethTwaps = wethTwaps.subList(windowSize - 1, blocks.size());
//printArraysInOneLine(subWethTwaps);
/////////////////////////////////////////////////////////////////////////////////
// pricer liquidity reserve TWAP
/////////////////////////////////////////////////////////////////////////////////
List<String> vusdLiq0Twap = calcTwap(vusdLiq0s, interval, windowSize);
//printArraysInOneLine(vusdLiq0Twap);
List<String> subVusdLiq0s = vusdLiq0s.subList(windowSize - 1, blocks.size());
//printArraysInOneLine(subVusdLiq0s);
List<String> vusdLiq1Twap = calcTwap(vusdLiq1s, interval, windowSize);
//printArraysInOneLine(vusdLiq1Twap);
List<String> subVusdLiq1s = vusdLiq1s.subList(windowSize - 1, blocks.size());
//printArraysInOneLine(subVusdLiq1s);
List<String> wethLiq0Twap = calcTwap(wethLiq0s, interval, windowSize);
printArraysInOneLine(wethLiq0Twap);
List<String> subWethLiq0s = wethLiq0s.subList(windowSize - 1, blocks.size());
printArraysInOneLine(subWethLiq0s);
List<String> wethLiq1Twap = calcTwap(wethLiq1s, interval, windowSize);
printArraysInOneLine(wethLiq1Twap);
List<String> subWethLiq1s = wethLiq1s.subList(windowSize - 1, blocks.size());
printArraysInOneLine(subWethLiq1s);
}
// current block#=13537865,10000vusd->usdc=9862.568695, vusdRes=1083.4437885867906, usdcRes=1071.4874892748078, twapVusd2USDC=0.9889645411809168
// current block#=13537865,10weth->usdc=44682.835373, usdcRes=165595.3153182826, wethRes=55.5528579071808, twapWeth2USDC=4467.622887771037
private static List<String> parseBlockLineForPricerQuoteInUniV3(String blockLine) {
List<String> ret = new ArrayList<String>(4);
String[] commaSplits = blockLine.split(",");
String[] blockHeights = commaSplits[0].split("=");
ret.add(blockHeights[1].trim());
String[] pricerQuotes = commaSplits[1].split("=");
ret.add(pricerQuotes[1].trim());
String[] liq0 = commaSplits[2].split("=");
ret.add(liq0[1].trim());
String[] liq1 = commaSplits[3].split("=");
ret.add(liq1[1].trim());
String[] poolTwap = commaSplits[4].split("=");
ret.add(poolTwap[1].trim());
return ret;
}
private static String printArraysInOneLine(List<String> data) {
StringBuilder sb = new StringBuilder();
for(String s : data) {
sb.append(s).append(",");
}
sb.setLength(sb.length() - 1);
String line = sb.toString();
System.out.println(line);
return line;
}
// for each quote, the value is multiplied by interval then added to an accumulative
// returned list contains series of twap = (diff_accumulative / interval * windowSize)
private static List<String> calcTwap(List<String> quotes, int interval, int windowSize){
List<String> ret = new ArrayList<String>(quotes.size() - windowSize);
List<Double> accumulatives = new ArrayList<Double>(quotes.size());
double accumulative = 0.0f;
for(int i = 0;i < quotes.size();i++) {
accumulatives.add(accumulative);
accumulative += Double.parseDouble(quotes.get(i)) * interval;
}
for(int i = windowSize - 1;i < accumulatives.size();i++) {
double accumulativeHigh = accumulatives.get(i);
double accumulativeLow = accumulatives.get(i + 1 - windowSize);
double twap = (accumulativeHigh - accumulativeLow) / (interval * windowSize);
ret.add(String.valueOf(twap));
}
return ret;
}
}
import matplotlib.pyplot as plt
import numpy as np
## vusd-usdc hack in Rai Pool#23 on Nov 2nd 2021 https://twitter.com/RariCapital/status/1455569653820973057
x_block = [13537873,13537874,13537875,13537876,13537877,13537878,13537879,13537880,13537881,13537882,13537883,13537884,13537885,13537886,13537887,13537888,13537889,13537890,13537891,13537892,13537893,13537894,13537895,13537896,13537897,13537898,13537899,13537900,13537901,13537902,13537903,13537904,13537905,13537906,13537907,13537908,13537909,13537910,13537911,13537912,13537913,13537914,13537915,13537916,13537917,13537918,13537919,13537920,13537921,13537922,13537923]
## vusd in-range liquidity twap in the pool
vusd_in_range_twap = [1061.774912815054,1061.774912815054,1061.7749128150538,1061.7749128150538,1061.7749128150535,1061.7749128150535,1061.7749128150535,1061.7749128150535,1061.7749128150533,1061.7749128150533,1061.774912815053,1061.774912815053,1061.7749128150529,1061.7749128150529,1061.7749128150526,1061.7749128150526,1061.7749128150524,1061.7749128150524,1061.7749128150522,1061.7749128150522,1061.7749128150522,1061.7749128150522,1061.7749128150522,1061.774912815052,1061.7749128150517,1061.7749128150517,1061.7749128150517,1061.7749128150515,1061.7749128150513,1061.7749128150513,1061.7749128150513,1061.774912815051,1061.7749128150508,1061.7749128150508,1061.7749128150508,1061.7749128150508,1061.7749128150506,1061.7749128150506,1061.7749128150506,1061.7749128150504,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1061.7749128150501,1040.1060370433145]
## vusd in-range liquidity spot in the pool
vusd_in_range_spot = [1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,1083.4437885867906,0,0]
## usdc in-range liquidity twap in the pool
usdc_in_range_twap = [1050.0577394893126,1050.0577394893126,1050.0577394893126,1050.0577394893128,1050.0577394893128,1050.0577394893128,1050.0577394893128,1050.0577394893128,1050.057739489313,1050.057739489313,1050.057739489313,1050.057739489313,1050.057739489313,1050.057739489313,1050.057739489313,1050.057739489313,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.0577394893132,1050.057739489313,1050.057739489313,1050.0577394893126,1050.0577394893126,1050.057739489312,1050.057739489312,1050.0577394893116,1050.0577394893116,1050.0577394893116,1050.0577394893114,1050.0577394893112,1050.057739489311,1050.0577394893107,1050.0577394893105,1050.0577394893103,1050.0577394893103,1028.627989703814]
## usdc in-range liquidity spot in the pool
usdc_in_range_spot = [1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,1071.4874892748078,0,0]
fig, ax = plt.subplots(2, 1)
## token0
ax[0].plot(x_block, vusd_in_range_twap, marker="v", color="r", label="pool token0 liquidity twap")
ax[0].plot(x_block, vusd_in_range_spot, marker=">", color="b", label="pool token0 liquidity spot")
ax[0].plot(x_block, np.divide(vusd_in_range_spot, vusd_in_range_twap), marker="^", color="g", label="ratio")
ax[0].ticklabel_format(useOffset=False, axis='x', style='plain')
ax[0].set_yscale("log")
ax[0].set(xlabel="Block Height", ylabel="Token0 Liquidity(log scale)", title="Pool Token0 Liquidity TWAP VS Spot")
ax[0].grid()
ax[0].legend(loc="center left")
## token1
ax[1].plot(x_block, usdc_in_range_twap, marker="v", color="r", label="pool token1 liquidity twap")
ax[1].plot(x_block, usdc_in_range_spot, marker=">", color="b", label="pool token1 liquidity spot")
ax[1].plot(x_block, np.divide(usdc_in_range_spot, usdc_in_range_twap), marker="^", color="g", label="ratio")
ax[1].ticklabel_format(useOffset=False, axis='x', style='plain')
ax[1].set_yscale("log")
ax[1].set(xlabel="Block Height", ylabel="Token1 Liquidity(log scale)", title="Pool Token 1 Liquidity TWAP VS Spot")
ax[1].grid()
ax[1].legend(loc="center left")
fig.savefig("pool-reserve-twap-vusd.png")
#plt.legend(loc="upper left")
plt.show()
import matplotlib.pyplot as plt
import numpy as np
## vusd-usdc hack in Rai Pool#23 on Nov 2nd 2021 https://twitter.com/RariCapital/status/1455569653820973057
x_block = [13537873,13537874,13537875,13537876,13537877,13537878,13537879,13537880,13537881,13537882,13537883,13537884,13537885,13537886,13537887,13537888,13537889,13537890,13537891,13537892,13537893,13537894,13537895,13537896,13537897,13537898,13537899,13537900,13537901,13537902,13537903,13537904,13537905,13537906,13537907,13537908,13537909,13537910,13537911,13537912,13537913,13537914,13537915,13537916,13537917,13537918,13537919,13537920,13537921,13537922,13537923]
## quoting price for 10000 vusd swapped to usdc
vusd_usdc_pricer_quote = [0.9665317321100008,0.9665317321100008,0.9665317321100008,0.9665317321100008,0.9665317321100008,0.966531732110001,0.966531732110001,0.966531732110001,0.966531732110001,0.966531732110001,0.966531732110001,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9665317321100012,0.9468065947200012]
## twap reading from uniswap v3 pool observe()
vusd_usdc_uni_twap = [0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,0.9889645411809168,1.7695532402418657,2313.5891045577014]
fig, ax = plt.subplots()
ax.plot(x_block, vusd_usdc_pricer_quote, marker="v", color="r", label="pricer twap quotes")
ax.plot(x_block, vusd_usdc_uni_twap, marker=">", color="b", label="uniswap v3 pool twap")
ax.plot(x_block, np.subtract(vusd_usdc_uni_twap, vusd_usdc_pricer_quote), marker="^", color="g", label="difference")
ax.ticklabel_format(useOffset=False, axis='x', style='plain')
ax.set_yscale("log")
ax.set(xlabel="Block Height", ylabel="TWAP(log scale)", title="Pricer Quote TWAP VS Uniswap V3 TWAP")
ax.grid()
fig.savefig("pool-pricer-twap-vusd.png")
plt.legend(loc="upper left")
plt.show()
current block#=13537923 10000vusd->usdc=0 vusdRes=0 usdcRes=0 twapVusd2USDC=2313.5891045577014
current block#=13537923 10weth->usdc=44825.695282 usdcRes=248466.778495772 wethRes=36.93158300228517 twapWeth2USDC=4475.250029930263
current block#=13537922 10000vusd->usdc=0 vusdRes=0 usdcRes=0 twapVusd2USDC=1.7695532402418657
current block#=13537922 10weth->usdc=44825.695282 usdcRes=248466.778495772 wethRes=36.93158300228517 twapWeth2USDC=4474.166458933348
current block#=13537921 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537921 10weth->usdc=44853.283603 usdcRes=82635.48771417835 wethRes=73.63766765422619 twapWeth2USDC=4473.912942692644
current block#=13537920 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537920 10weth->usdc=44853.283603 usdcRes=82635.48771417835 wethRes=73.63766765422619 twapWeth2USDC=4473.376132188867
current block#=13537919 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537919 10weth->usdc=44858.416025 usdcRes=123956.33035033983 wethRes=64.43134837348825 twapWeth2USDC=4472.458484539271
current block#=13537918 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537918 10weth->usdc=44778.54414 usdcRes=206946.9782556378 wethRes=46.18872029827553 twapWeth2USDC=4472.176742616569
current block#=13537917 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537917 10weth->usdc=44791.867767 usdcRes=331139.99988110305 wethRes=18.47410253852337 twapWeth2USDC=4471.7698133946715
current block#=13537916 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537916 10weth->usdc=44791.867767 usdcRes=331139.99988110305 wethRes=18.47410253852337 twapWeth2USDC=4470.98736126584
current block#=13537915 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537915 10weth->usdc=44811.060338 usdcRes=82813.97782483703 wethRes=73.87055269047745 twapWeth2USDC=4470.368948375539
current block#=13537914 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537914 10weth->usdc=44784.641541 usdcRes=289740.2562084852 wethRes=27.71184657508998 twapWeth2USDC=4469.83330803922
current block#=13537913 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537913 10weth->usdc=44725.830843 usdcRes=124099.91643328441 wethRes=64.6997818970644 twapWeth2USDC=4469.596424995306
current block#=13537912 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537912 10weth->usdc=44725.830843 usdcRes=124099.91643328441 wethRes=64.6997818970644 twapWeth2USDC=4469.569608837991
current block#=13537911 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537911 10weth->usdc=44725.830843 usdcRes=124099.91643328441 wethRes=64.6997818970644 twapWeth2USDC=4469.556200819667
current block#=13537910 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537910 10weth->usdc=44725.830843 usdcRes=124099.91643328441 wethRes=64.6997818970644 twapWeth2USDC=4469.415419055635
current block#=13537909 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537909 10weth->usdc=44726.893246 usdcRes=165470.69187374544 wethRes=55.45556949943095 twapWeth2USDC=4469.374451650407
current block#=13537908 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537908 10weth->usdc=44726.893246 usdcRes=165470.69187374544 wethRes=55.45556949943095 twapWeth2USDC=4469.31486336766
current block#=13537907 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537907 10weth->usdc=44708.514145 usdcRes=414050.39171386074 wethRes=0 twapWeth2USDC=4469.259000074132
current block#=13537906 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537906 10weth->usdc=44706.837499 usdcRes=372636.03625351196 wethRes=9.25765239641537 twapWeth2USDC=4469.234420446191
current block#=13537905 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537905 10weth->usdc=44706.837499 usdcRes=372636.03625351196 wethRes=9.25765239641537 twapWeth2USDC=4469.2277169347635
current block#=13537904 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537904 10weth->usdc=44706.837499 usdcRes=372636.03625351196 wethRes=9.25765239641537 twapWeth2USDC=4469.205371969263
current block#=13537903 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537903 10weth->usdc=44710.55852 usdcRes=414050.39171386074 wethRes=0 twapWeth2USDC=4469.167385784324
current block#=13537902 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537902 10weth->usdc=44710.55852 usdcRes=414050.39171386074 wethRes=0 twapWeth2USDC=4469.1159932244855
current block#=13537901 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537901 10weth->usdc=44728.98597 usdcRes=165470.69187374544 wethRes=55.45556949943095 twapWeth2USDC=4469.125675835504
current block#=13537900 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537900 10weth->usdc=44742.752148 usdcRes=289595.4295312537 wethRes=27.72570526983059 twapWeth2USDC=4469.121951751861
current block#=13537899 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537899 10weth->usdc=44742.752148 usdcRes=289595.4295312537 wethRes=27.72570526983059 twapWeth2USDC=4468.572311036966
current block#=13537898 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537898 10weth->usdc=44640.440402 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4468.248367484416
current block#=13537897 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537897 10weth->usdc=44640.440402 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4468.241665451995
current block#=13537896 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537896 10weth->usdc=44640.440402 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4468.217091419085
current block#=13537895 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537895 10weth->usdc=44640.440402 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4468.210389433574
current block#=13537894 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537894 10weth->usdc=44640.440402 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4468.208155440634
current block#=13537893 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537893 10weth->usdc=44640.440402 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4468.196240830491
current block#=13537892 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537892 10weth->usdc=44648.236688 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4468.199219480054
current block#=13537891 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537891 10weth->usdc=44648.236688 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4468.194751506459
current block#=13537890 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537890 10weth->usdc=44667.937694 usdcRes=413843.428610928 wethRes=0 twapWeth2USDC=4468.024971820578
current block#=13537889 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537889 10weth->usdc=44627.263878 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4468.007100649973
current block#=13537888 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537888 10weth->usdc=44627.263878 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4468.045076972952
current block#=13537887 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537887 10weth->usdc=44627.263878 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4468.103159032433
current block#=13537886 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537886 10weth->usdc=44627.16729 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4468.132200345297
current block#=13537885 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537885 10weth->usdc=44627.16729 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4468.150072016277
current block#=13537884 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537884 10weth->usdc=44643.506008 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4468.146348745596
current block#=13537883 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537883 10weth->usdc=44643.506008 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4468.1441147846745
current block#=13537882 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537882 10weth->usdc=44642.427857 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4468.1441147846745
current block#=13537881 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537881 10weth->usdc=44642.427857 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4468.1441147846745
current block#=13537880 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537880 10weth->usdc=44642.427857 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4468.1441147846745
current block#=13537879 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537879 10weth->usdc=44661.786257 usdcRes=372449.7741176027 wethRes=9.262282148471984 twapWeth2USDC=4468.132200345297
current block#=13537878 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537878 10weth->usdc=44652.081917 usdcRes=289668.67360984907 wethRes=27.78823577619866 twapWeth2USDC=4468.0964572178
current block#=13537877 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537877 10weth->usdc=44652.081917 usdcRes=289668.67360984907 wethRes=27.78823577619866 twapWeth2USDC=4468.09050005768
current block#=13537876 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537876 10weth->usdc=44652.081917 usdcRes=289668.67360984907 wethRes=27.78823577619866 twapWeth2USDC=4468.0420984261455
current block#=13537875 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537875 10weth->usdc=44654.707035 usdcRes=331058.18915177125 wethRes=18.52502739947803 twapWeth2USDC=4468.041353789763
current block#=13537874 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537874 10weth->usdc=44658.324029 usdcRes=331058.18915177125 wethRes=18.52502739947803 twapWeth2USDC=4467.956466054792
current block#=13537873 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537873 10weth->usdc=44658.324029 usdcRes=331058.18915177125 wethRes=18.52502739947803 twapWeth2USDC=4467.937105920043
current block#=13537872 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537872 10weth->usdc=44658.324029 usdcRes=331058.18915177125 wethRes=18.52502739947803 twapWeth2USDC=4467.931148972381
current block#=13537871 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537871 10weth->usdc=44658.324029 usdcRes=331058.18915177125 wethRes=18.52502739947803 twapWeth2USDC=4467.917745869183
current block#=13537870 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537870 10weth->usdc=44658.324029 usdcRes=331058.18915177125 wethRes=18.52502739947803 twapWeth2USDC=4467.898385902212
current block#=13537869 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537869 10weth->usdc=44682.61837 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.896896677462
current block#=13537868 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537868 10weth->usdc=44682.61837 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.861155432278
current block#=13537867 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537867 10weth->usdc=44682.61837 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.765846842947
current block#=13537866 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537866 10weth->usdc=44682.835373 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.747976708789
current block#=13537865 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537865 10weth->usdc=44682.835373 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.622887771037
current block#=13537864 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537864 10weth->usdc=44682.835373 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.64224654424
current block#=13537863 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537863 10weth->usdc=44682.835373 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.545453517061
current block#=13537862 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537862 10weth->usdc=44682.835373 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.487378707342
current block#=13537861 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537861 10weth->usdc=44682.835373 usdcRes=165595.3153182826 wethRes=55.5528579071808 twapWeth2USDC=4467.187337550044
current block#=13537860 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537860 10weth->usdc=44689.966632 usdcRes=206999.3190014983 wethRes=46.29289092405431 twapWeth2USDC=4467.127778427179
current block#=13537859 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537859 10weth->usdc=44690.965105 usdcRes=248405.39283302723 wethRes=37.03338690458154 twapWeth2USDC=4467.063008782406
current block#=13537858 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537858 10weth->usdc=44692.05044 usdcRes=248405.39283302723 wethRes=37.03338690458154 twapWeth2USDC=4466.748107685466
current block#=13537857 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537857 10weth->usdc=44697.104562 usdcRes=289813.53691652644 wethRes=27.774345825581936 twapWeth2USDC=4466.7146088752
current block#=13537856 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537856 10weth->usdc=44697.104562 usdcRes=289813.53691652644 wethRes=27.774345825581936 twapWeth2USDC=4466.501711197643
current block#=13537855 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537855 10weth->usdc=44625.400418 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.440672476578
current block#=13537854 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537854 10weth->usdc=44625.400418 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.495011785073
current block#=13537853 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537853 10weth->usdc=44625.400418 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.526275796407
current block#=13537852 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537852 10weth->usdc=44625.400418 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.531486486235
current block#=13537851 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537851 10weth->usdc=44625.400418 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.576894183484
current block#=13537850 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537850 10weth->usdc=44625.400418 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.594759633537
current block#=13537849 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537849 10weth->usdc=44626.491475 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.634957157419
current block#=13537848 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537848 10weth->usdc=44626.86584 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4466.668455370338
current block#=13537847 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537847 10weth->usdc=44634.082573 usdcRes=124131.303613747 wethRes=64.84570100298133 twapWeth2USDC=4466.681854725846
current block#=13537846 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537846 10weth->usdc=44634.082573 usdcRes=124131.303613747 wethRes=64.84570100298133 twapWeth2USDC=4466.687810007865
current block#=13537845 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537845 10weth->usdc=44637.53025 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.730986039938
current block#=13537844 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537843 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537843 10weth->usdc=44638.614425 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.750340948419
current block#=13537844 10weth->usdc=44638.614425 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.74140790332
current block#=13537842 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537842 10weth->usdc=44638.614425 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.769695940766
current block#=13537841 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537841 10weth->usdc=44638.614425 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.842650127273
current block#=13537840 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537840 10weth->usdc=44638.519106 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.980373012847
current block#=13537839 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537839 10weth->usdc=44638.465201 usdcRes=165512.54249406123 wethRes=55.580639891957624 twapWeth2USDC=4466.984839772111
current block#=13537838 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537838 10weth->usdc=44645.689552 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4466.992284380821
current block#=13537837 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537837 10weth->usdc=44644.831092 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4466.9989845392765
current block#=13537836 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537836 10weth->usdc=44644.831092 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4467.0019623906965
current block#=13537835 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537835 10weth->usdc=44644.831092 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4467.017596143251
current block#=13537834 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537834 10weth->usdc=44644.831092 usdcRes=206895.85038445223 wethRes=46.316041999280465 twapWeth2USDC=4467.097999163532
current block#=13537833 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537833 10weth->usdc=44646.192476 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4467.134478788865
current block#=13537832 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537832 10weth->usdc=44646.192476 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4467.214883912936
current block#=13537831 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537831 10weth->usdc=44646.192476 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4467.275188705739
current block#=13537830 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537830 10weth->usdc=44646.192476 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4467.355596362483
current block#=13537829 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537829 10weth->usdc=44646.192476 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4467.394311676353
current block#=13537828 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537828 10weth->usdc=44646.433296 usdcRes=248281.22738866453 wethRes=37.051907301724285 twapWeth2USDC=4467.4449399007335
current block#=13537827 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537827 10weth->usdc=44689.648439 usdcRes=206999.3190014983 wethRes=46.29289092405431 twapWeth2USDC=4467.480677816345
current block#=13537826 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537826 10weth->usdc=44689.648439 usdcRes=206999.3190014983 wethRes=46.29289092405431 twapWeth2USDC=4467.447173512085
current block#=13537825 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537825 10weth->usdc=44626.048687 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4467.479188730823
current block#=13537824 10000vusd->usdc=9862.568695 vusdRes=1083.4437885867906 usdcRes=1071.4874892748078 twapVusd2USDC=0.9889645411809168
current block#=13537824 10weth->usdc=44625.858007 usdcRes=41375.03247023375 wethRes=83.37721297256518 twapWeth2USDC=4467.5528990600815
import matplotlib.pyplot as plt
import numpy as np
## weth-usdc pool in uniswap v3 0.05% https://info.uniswap.org/#/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640
x_block = [13537873,13537874,13537875,13537876,13537877,13537878,13537879,13537880,13537881,13537882,13537883,13537884,13537885,13537886,13537887,13537888,13537889,13537890,13537891,13537892,13537893,13537894,13537895,13537896,13537897,13537898,13537899,13537900,13537901,13537902,13537903,13537904,13537905,13537906,13537907,13537908,13537909,13537910,13537911,13537912,13537913,13537914,13537915,13537916,13537917,13537918,13537919,13537920,13537921,13537922,13537923]
## usdc in-range liquidity twap in the pool
usdc_in_range_twap = [170514.71134931935,176308.3744829501,182102.03761658084,184583.21501958632,186236.60211175334,187064.35103617702,187892.0999606007,190375.47089517946,189547.76335509523,188720.055815011,187892.34827492677,187892.34827492674,187892.34827492674,184581.93191664238,181271.51555835802,177961.09920007363,175478.34899959707,172995.59879912055,177962.21652145789,179617.59021934995,181272.96391724204,181272.96391724204,181272.96391724204,182100.58869484832,182928.2134724546,185410.96367293113,187893.7138734077,192858.1218146281,197822.5297558485,200304.44294391875,207757.95012879127,215211.45731366382,221836.6773893294,223493.12737606908,225149.57736280878,228462.47734042545,226803.78332123984,225973.21077868482,225143.30280098488,224313.3948232849,223483.48684558494,222653.57886788496,225136.47768568902,223480.85093582008,226791.7446270765,230102.63831833293,230929.67157707998,226787.63440105141,221819.18037229954,216850.72634354766,215198.89813042767]
## usdc in-range liquidity spot in the pool
usdc_in_range_spot = [331058.18915177125,331058.18915177125,331058.18915177125,289668.67360984907,289668.67360984907,289668.67360984907,372449.7741176027,206895.85038445223,206895.85038445223,206895.85038445223,206895.85038445223,206895.85038445223,41375.03247023375,41375.03247023375,41375.03247023375,41375.03247023375,41375.03247023375,413843.428610928,248281.22738866453,248281.22738866453,165512.54249406123,165512.54249406123,165512.54249406123,165512.54249406123,165512.54249406123,165512.54249406123,289595.4295312537,289595.4295312537,165470.69187374544,414050.39171386074,414050.39171386074,372636.03625351196,372636.03625351196,372636.03625351196,414050.39171386074,165470.69187374544,165470.69187374544,124099.91643328441,124099.91643328441,124099.91643328441,124099.91643328441,289740.2562084852,82813.97782483703,331139.99988110305,331139.99988110305,206946.9782556378,123956.33035033983,82635.48771417835,82635.48771417835,248466.778495772,248466.778495772]
## weth in-range liquidity twap in the pool
weth_in_range_twap = [52.60929212755235,51.312248416090604,50.015204704628864,49.45984743413734,49.08975433118022,48.90448090066971,48.71920747015919,48.163414967094155,48.34869766104528,48.53398035499641,48.71926304894753,48.71926304894754,48.719263048947546,49.460486468413244,50.201709887878934,50.94293330734463,51.49886476895678,52.05479623056893,50.943183432729775,50.57260878092511,50.202034129120435,50.202034129120435,50.202034129120435,50.01673290689996,49.83143168467948,49.27550022306733,48.71956876145518,47.606538607400495,46.49350845334581,45.935075583883126,44.26753132443183,42.599987064980525,41.11759585345753,40.74726198487421,40.376928116290884,39.63626037819925,40.00470403009624,40.187957601603784,40.37089608140145,40.55383456119912,40.73677304099678,40.91971152079445,40.36289129415263,40.729245189818556,39.987670082445405,39.24609497507226,39.058812222894154,39.97693864237436,41.07919144746933,42.1814442525643,42.54957536462045]
## weth in-range liquidity spot in the pool
weth_in_range_spot = [18.52502739947803,18.52502739947803,18.52502739947803,27.78823577619866,27.78823577619866,27.78823577619866,9.262282148471984,46.316041999280465,46.316041999280465,46.316041999280465,46.316041999280465,46.316041999280465,83.37721297256518,83.37721297256518,83.37721297256518,83.37721297256518,83.37721297256518,0,37.051907301724285,37.051907301724285,55.580639891957624,55.580639891957624,55.580639891957624,55.580639891957624,55.580639891957624,55.580639891957624,27.72570526983059,27.72570526983059,55.45556949943095,0,0,9.25765239641537,9.25765239641537,9.25765239641537,0,55.45556949943095,55.45556949943095,64.6997818970644,64.6997818970644,64.6997818970644,64.6997818970644,27.71184657508998,73.87055269047745,18.47410253852337,18.47410253852337,46.18872029827553,64.43134837348825,73.63766765422619,73.63766765422619,36.93158300228517,36.93158300228517]
fig, ax = plt.subplots(2, 1)
## token0
ax[0].plot(x_block, usdc_in_range_twap, marker="v", color="r", label="pool token0 liquidity twap")
ax[0].plot(x_block, usdc_in_range_spot, marker=">", color="b", label="pool token0 liquidity spot")
ax[0].plot(x_block, np.divide(usdc_in_range_spot, usdc_in_range_twap), marker="^", color="g", label="ratio")
ax[0].ticklabel_format(useOffset=False, axis='x', style='plain')
ax[0].set_yscale("log")
ax[0].set(xlabel="Block Height", ylabel="Token0 Liquidity(log scale)", title="Pool Token0 Liquidity TWAP VS Spot")
ax[0].grid()
ax[0].legend(loc="center left")
## token1
ax[1].plot(x_block, weth_in_range_twap, marker="v", color="r", label="pool token1 liquidity twap")
ax[1].plot(x_block, weth_in_range_spot, marker=">", color="b", label="pool token1 liquidity spot")
ax[1].plot(x_block, np.divide(weth_in_range_spot, weth_in_range_twap), marker="^", color="g", label="ratio")
ax[1].ticklabel_format(useOffset=False, axis='x', style='plain')
ax[1].set_yscale("log")
ax[1].set(xlabel="Block Height", ylabel="Token1 Liquidity(log scale)", title="Pool Token 1 Liquidity TWAP VS Spot")
ax[1].grid()
ax[1].legend(loc="center left")
fig.savefig("pool-reserve-twap-vusd.png")
#plt.legend(loc="upper left")
plt.show()
import matplotlib.pyplot as plt
import numpy as np
## weth-usdc pool in uniswap v3 0.05% https://info.uniswap.org/#/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640
x_block = [13537873,13537874,13537875,13537876,13537877,13537878,13537879,13537880,13537881,13537882,13537883,13537884,13537885,13537886,13537887,13537888,13537889,13537890,13537891,13537892,13537893,13537894,13537895,13537896,13537897,13537898,13537899,13537900,13537901,13537902,13537903,13537904,13537905,13537906,13537907,13537908,13537909,13537910,13537911,13537912,13537913,13537914,13537915,13537916,13537917,13537918,13537919,13537920,13537921,13537922,13537923]
## quoting price for 10 weth swapped to usdc
weth_usdc_pricer_quote = [4376.127082260001,4376.1920143040015,4376.256564988002,4376.186682180001,4376.111549136002,4376.122846378003,4376.134625260002,4376.165812822002,4376.158283584003,4376.150754346003,4376.143225108003,4376.140574940004,4376.137924772003,4376.102597168004,4376.067269564004,4376.030418216004,4376.008015570003,4375.985505114004,4376.044151652003,4376.063396178003,4376.082640704002,4376.086292658002,4376.092112962001,4376.104828620002,4376.117544278001,4376.144693402001,4376.172591256001,4376.407294716001,4376.641998176,4376.849169280002,4377.019485484,4377.189801688,4377.352675849998,4377.3721417239985,4377.391607597998,4377.424535007998,4377.4963912899975,4377.570244517999,4377.656235457998,4377.742226397999,4377.8282173379985,4377.914208277999,4378.117820613998,4378.374270543998,4378.592769337998,4378.811268131997,4379.003119671998,4379.403303663998,4379.793222811996,4380.183141959996,4380.517884465995]
## twap reading from uniswap v3 pool observe()
weth_usdc_uni_twap = [4467.937105920043,4467.956466054792,4468.041353789763,4468.0420984261455,4468.09050005768,4468.0964572178,4468.132200345297,4468.1441147846745,4468.1441147846745,4468.1441147846745,4468.1441147846745,4468.146348745596,4468.150072016277,4468.132200345297,4468.103159032433,4468.045076972952,4468.007100649973,4468.024971820578,4468.194751506459,4468.199219480054,4468.196240830491,4468.208155440634,4468.210389433574,4468.217091419085,4468.241665451995,4468.248367484416,4468.572311036966,4469.121951751861,4469.125675835504,4469.1159932244855,4469.167385784324,4469.205371969263,4469.2277169347635,4469.234420446191,4469.259000074132,4469.31486336766,4469.374451650407,4469.415419055635,4469.556200819667,4469.569608837991,4469.596424995306,4469.83330803922,4470.368948375539,4470.98736126584,4471.7698133946715,4472.176742616569,4472.458484539271,4473.376132188867,4473.912942692644,4474.166458933348,4475.250029930263]
fig, ax = plt.subplots()
ax.plot(x_block, weth_usdc_pricer_quote, marker="v", color="r", label="pricer twap quotes")
ax.plot(x_block, weth_usdc_uni_twap, marker=">", color="b", label="uniswap v3 pool twap")
ax.plot(x_block, np.subtract(weth_usdc_uni_twap, weth_usdc_pricer_quote), marker="^", color="g", label="difference")
ax.ticklabel_format(useOffset=False, axis='x', style='plain')
ax.set_yscale("log")
ax.set(xlabel="Block Height", ylabel="TWAP(log scale)", title="Pricer Quote TWAP VS Uniswap V3 TWAP")
ax.grid()
fig.savefig("pool-pricer-twap-weth.png")
plt.legend(loc="upper left")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment