npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@keydonix/uniswap-oracle-ethers-sdk-adapter

v1.0.4

Published

Adapter for using @keydonix/uniswap-oracle-sdk with legacy providers like raw JSON-RPC, ethers, web3.js, etc.

Downloads

5

Readme

uniswap-oracle

A general purpose price feed oracle built on Uniswap v2 that supports arbitrary time windows (up to 256 blocks) and doesn't require any active maintenance.

🎊 Finally, an on-chain trustless and censorship resistant oracle! 🎉

Unlike other Uniswap v2 based oracles, this one does not require regular maintenance by either an altruistic or incentivized party. Anyone with access to an Ethereum node can generate a proof of Uniswap's storage from up to 256 blocks ago and submit it for on-chain validation. You can then use that validated proof to calculate the average price between the current block and the supplied proof's block so you are protected from short-term price manipulation.

Community/Support

Discord Twitter Follow

In the News

https://medium.com/@epheph/using-uniswap-v2-oracle-with-storage-proofs-3530e699e1d3

Usage

npm install @keydonix/uniswap-oracle-contracts @keydonix/uniswap-oracle-sdk

Optionally:

npm install @keydonix/uniswap-oracle-sdk-adapter

See a fully functional example in demo/contracts/PriceEmitter.sol and demo/source/demo.ts. Documentation here is a bit terse because the example is so small that it is probably easier to just read it!

pragma solidity 0.6.8;
pragma experimental ABIEncoderV2;

import { UniswapOracle } from  '@Keydonix/uniswap-oracle-contracts/source/UniswapOracle.sol';
import { IUniswapV2Pair } from "@Keydonix/uniswap-oracle-contracts/source/IUniswapV2Pair.sol";

contract PriceEmitter is UniswapOracle {
	event Price(uint256 price);

	function emitPrice(IUniswapV2Pair exchange, address denominationToken, uint8 minBlocksBack, uint8 maxBlocksBack, UniswapOracle.ProofData memory proofData) public returns (uint256 price, uint256 blockNumber) {
		(price, blockNumber) = getPrice(exchange, denominationToken, minBlocksBack, maxBlocksBack, proofData);
		emit Price(price);
	}
}
import * as OracleSdk from '@keydonix/uniswap-oracle-sdk'
import * as OracleSdkAdapter from '@keydonix/uniswap-oracle-sdk-adapter'

// create the getters the SDK needs from an Ethereum instance off the window.  you could use `window.web3.currentProvider` instead of `window.ethereum` if that is what is available
const getStorageAt = OracleSdkAdapter.getStorageAtFactory(window.ethereum)
const getProof = OracleSdkAdapter.getProofFactory(window.ethereum)
const getBlockByNumber = OracleSdkAdapter.getBlockByNumberFactory(window.ethereum)

// estimate the moving average price off-chain for presentation in your UI
const estimatedPrice = OracleSdk.getPrice(getStorageAt, getblockByNumber, uniswapExchangeAddress, denominationTokenAddress, blockNumber)

// get the proof from the SDK
const proof = await OracleSdk.getProof(getStorageAt, getProof, getBlockByNumber, uniswapExchangeAddress, denominationTokenAddress, blockNumber)

// inside this contract call we'll have trustless access to a Uniswap average price between `blockNumber` and `currentBlockNumber`
await priceEmitter.emitPrice(uniswapExchangeAddress, denominationTokenAddress, minBlocksBackAllowed, maxBlocksBackAllowed, proof)

Developing

Tool Requirements

NodeJS, NPM, Docker

Optional

VSCode (life is simpler with this, but not required)

VSCode

If you are using VSCode, you can run npm install in each directory (one time operation) and then Tasks Run Task > all the things to bootstrap everything. From there you can Debug: Select and Start Debugging > run demo or Debug: Select and Start Debugging > run tests.

Building

Contracts

These are published to NPM as-is, demo project compiles and tests them.

SDK

cd sdk
npm install # one time

npm run build

SDK Adapter

cd sdk-adapter
npm install # one time

npm run build

Demo

Depends on Contracts and SDK

cd demo
npm install # one time

npm run build # compiles contracts

Running

cd demo
docker-compose up --force-recreate --always-recreate-deps --abort-on-container-exit --remove-orphans --renew-anon-volumes
npm run demo

Testing

cd demo
docker-compose up --force-recreate --always-recreate-deps --abort-on-container-exit --remove-orphans --renew-anon-volumes
npm run test