Coder Social home page Coder Social logo

tacoinfra / harbinger-contracts Goto Github PK

View Code? Open in Web Editor NEW
10.0 8.0 7.0 316 KB

This repository contains reference implementations of the Harbinger Price Oracle and normalizer contracts on the Tezos network written in SmartPy.

Home Page: https://github.com/tacoinfra/harbinger

License: MIT License

Python 98.93% Makefile 1.07%
tezos tezos-blockchain harbinger defi blockchain cryptocurrency oracle

harbinger-contracts's Introduction

Harbinger Contracts

This repository contains reference implementations for the smart contracts that make up Harbinger. To get started with Harbinger, visit the main documentation.

This library provides functionality for interacting with the Harbinger oracle system. Users who want to post prices might also be interested in Harbinger CLI or Harbinger Poster which is a hosted component providing similar functionality for posting data to Harbinger. Entities who wish to sign prices for Harbinger may want to look at Harbinger Signer. Developers of new Harbinger components may be interested in harbinger-lib.

File Structure

The following source files produce oracle and normalizer contracts:

  • oracle.py: The Harbinger oracle contract
  • normalizer.py: The Harbinger normalizer contract

For convenience, these two contracts are precompiled to Michelson in oracle.tz and normalizer.tz, respectively. If you wish to compile the contracts yourself, please see 'Building and Testing' below.

Additionally, the following files provide helper functionality and are not top-level contracts:

  • fifo_queue.py: A FIFO queue implementation
  • common.py: Common utility functions

Building and Testing

Harbinger contracts are written in SmartPy. Please consult the SmartPy Documentation for instructions on how to install and get started with the SmartPy command line tools.

You can run tests and compile with:

$ make all

To manually compile a contract:

$ make compile-minter
$ make compile-normalizer

To manually test a contract:

$ make test-minter
$ make test-normalizer

Contract Specifications

The provided contracts are reference implementations for a Harbinger implementation. It is possible to provide alternative implementations of these contracts as long as they conform to the same ABI.

Oracle Contract Specifications

Oracle contracts are bound to a single price feed and can contain an unlimited number of assets. All updates must be monotonically increasing in start time.

Specifically, the oracle contract can be configured with the following parameters:

  • Signer Public Key: The public key of the signer which provides the price feed for the oracle.
  • Asset List: A list of assets that the oracle will keep track of. Higher numbers of assets lead to increased gas and storage fees when interacting with the oracle.

An oracle contract has the following entrypoints:

  • update: Receives an signed set of updates to the oracle contract.
  • push: Pushes the data in the Oracle to a normalizer contract.
  • revoke: Revokes an oracle contract by removing the signer public key. This effectively triggers an emergency shutdown of the Oracle.

Normalizer Contract Specifications

Normalizer contracts normalize a single asset and can only receive updates from one Oracle. All updates must be monotonically increasing in start time.

Specifically, the normalizer contract can be configured with the following parameters:

  • Oracle Contract Address: The address of the oracle contract which provides updates.
  • Asset Name: The name of the asset that the contract will normalize.
  • Number of Data Points:: The number of data points to store and normalize. Higher numbers of data points lead to increased gas and storage fees when interactin with the normalizer.

A normalizer contract has the following entrypoints:

  • update: Receives data from an oracle contract.

Credits

Harbinger is written and maintained by Luke Youngblood and Keefer Taylor.

harbinger-contracts's People

Contributors

decentralgabe avatar keefertaylor avatar lyoungblood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

harbinger-contracts's Issues

Use sp.compute() in normalizer.py

sp.compute() should give us better gas optimizations. I've applied the change in oracle.py. If I apply it in normalizer.py, then running ./compile_smartpy.sh results in

Running Tests Before Compilation
>> Testing Oracle 
;[[SmartPy.sh:]]
  ## SmartPy Scenario `oracle`
    Scenario-interpretation: There were ERRORS :(
      (see also log: `./.smartpy_out/scenario-interpreter-log.txt`):
      Declaration Error
      
      
      Variable name "compute_-1" already in use.
      (line -1)

I'm not sure why this is because normalizer is not imported by oracle.py.

Enable Tests

There are two smartpy tests which don't work because smartpy doesn't support the secp256k1 curve. We should enable these when smartpy has the support we need.

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.