Code Monkey home page Code Monkey logo

localchainlink's Introduction

Chaos Labs - Chainlink Collaboration

This repository hosts a tool for deploying Chainlink price feeds into the LocalTerra ecosystem along with a CLI utility for mocking Chainlink Oracle prices Chainlink Data Feeds within LocalTerra.

In this repository

  • Chainlink feeds deployer - Since today LocalTerra comes without any of the main-net/testnets history or data, meaning dApps using Chainlink have no way of testing their integration with Chainlink. Chainlink deployer answer that by deploying oracle price feeds to LocalTerra on its start.
  • CLI - a tool designed to give developers control of the Chainlink feeds within LocalTerra. This will enable truly integration and e2e testing for Chainlink dependent dApps.

Navigate to our Quickstart section to get the repo up and running.

For a full deep dive to the project architecture please visit the Chaos Labs blog.

Why is Mocking Oracle values useful in testing?

Oracle return values trigger internal state changes in web3 applications. When working on local development environment, once feeds are deployed, the return values are constant. This is because the Chainlink protocol only writes updated values to mainnet or public testnets. Chaos Labs aims to streamline developer productivity while also making it easier to test applications, This tool gives developers the ability to mock return values easily. Now we can test how our contracts / applications react to different types of external data ๐Ÿค—. Below, we provide some specific use cases for mocking oracle return values.

Use Cases

LocalChainlink is build for dApp developers to better test the application's integration flows with chainlink. By mocking the returned price developers can test their application's behavior in various market conditions both in development phase as well as part of their CI\CD pipelines.

Moreover, DeFi protocols and applications are at high risk due to volatile market conditions and a myriad of security vectors. Mocking Chainlink Oracle return values in a controlled, siloed testing environment allows us to address 2 common vectors.

Volatile Market Conditions

Volatility is a DeFi constant and is something that all protocols and applications should test for thoroughly. Internal application and protocol state is often a direct result of Oracle returns values. To further illustrate this let's use an example.

Imagine a lending protocol (Maker, AAVE, Benqi, Spectral.finance, etc..) that accepts Ethereum as collateral against stablecoin loans. What happens on a day like Black Thursday, when Ethereum prices cascade negatively to the tune of ~70% in a 48 hour time frame? Well, a lot of things happen ๐Ÿคฆ.

Black Thursday Img

One critical aspect of responding to market volatility is protocol keepers triggering liquidations and thus ensuring protocol solvency.

With the ability to control Oracle return values, simulating such scenarios in your local development environment is possible.

Oracle Manipulation

Oracle manipulation is an additional attack vector. With this method, malicious actors research data sources that various oracle consume as sources of truth. When actors possess the ability to manipulate the underlying data source they trigger downstream effects, manifesting in altered Oracle return values. As a result of manipulated data, actors and contracts can trigger various unwanted behaviors such as modified permissions, transaction execution, emergency pausing / shutdown and more.

With the ability to manipulate Chainlink Oracle return values, simulating such scenarios in your local development environment is possible.

Pre-requisites

  • node (version 16.14)
  • docker
  • docker-compose
  • typescript installed globally such that the tsc compiler is available
  • ts-node

Quickstart

  1. git clone https://github.com/ChaosLabsInc/LocalChainlink.git
  2. cd LocalChainlink
  3. npm i - Installing project libs
  4. In a separate terminal window (spwan a new window in iTerm with cdm+D) run: docker-compose up
  5. npm run cli

After running the quickstart you should have the following: 2 terminals, 1 running docker-compose of localterra with chainlink depolyer, another running the cli-tool and it should look like this:

Setup screenshot 1

Once Chainlink LUNA\USD feed is deployed the terminal will look as follows:

Setup screenshot 2

Recommended Usage

This repo is meant to serve as an implementation spec for deploying price feeds and mocking oracle return values. This is a resource and reference for smart contract developers to implement such strategies and practices as part of their development lifecycle.

Example flow

  1. View the deployed price feeds addresses
  2. Mock price for selected price feed a. select the price feed to configure b. Set the desired price value returned by the price feed c. Mock ๐Ÿค ๐Ÿ’ฅ
  3. Deploy new price feed a. enter the feed name b. set initial price for feed c. set feed decimals d. deploy

asciicast

Start and reset LocalChainlink

  • Start LocalTerra:
$ docker-compose up

Reset the world state:

$ docker-compose up

PR Requests

Before submitting a PR please run the test suite with npm run test.

tests

CLI improvements. Have an idea to make this repo more user friendly? Let us know, or better yet, make a pull request :)

localchainlink's People

Contributors

natanela avatar yhayun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.