dirtoracle

command module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 2 Imported by: 0

README

dirtoracle

MTG DIRT Oracle, feed real life data to the MTG Network.

How it works

A Price Data consists a unix timestamp, asset id, price and a CosiSignature. The CosiSignature is an aggregated BLST signature signed by different MTG Node.

PriceData model:

type PriceData struct {
    Timestamp int64           `json:"t,omitempty"`
    AssetID   string          `json:"a,omitempty"`
    Price     decimal.Decimal `gorm:"TYPE:DECIMAL(16,8);" json:"p,omitempty"`
    Signature *CosiSignature  `gorm:"TYPE:TEXT;" json:"s,omitempty"`
}

The oracle system will generate Price Datas every 5 minutes OR whenever the asset's price change greater than 1%. The Datas will be sent to the subscribers via Mixin Transfers, putting the data in the transfer's memo.

Prepare Price Proposal

The MTG Node will collect prices from different sources, generate new price proposals, and send them to the specific Mixin Group.

The param "--feeds feeds.json" claims its feeds and data sources.

Exchange Interface hanldes the data source prices, all exchanges were implemented in Exchanges Package.

type (
    Handler interface {
        OnTicker(ctx context.Context, ticker *core.Ticker) error
    }

    Interface interface {
        Name() string
        // Subscribe subscribe exchange market events
        Subscribe(ctx context.Context, a *core.Asset, handler Handler) error
    }
)

The Market Worker will collect prices every short seconds, store the latest ticker data.

The prices from different sources will be Aggregated:

  • drop old prices (collected before 15s)
  • average price with 24 hour volumes weighted

Every second, the Oracle Worker will try to submit a new Price Proposal: the proposal will be sent to the other Nodes only if the Price Change is greater than 1% OR the duration since last submit is longer than 5 mins.

Generate Price Data

When a node received a new Price Proposal, it will validate the proposal. A proposal will be dropped if a newer proposal was found in cache OR the price diff bewteen local price and proposal price was greater 1%.

If the proposal passed the validation, the node will sign the proposal message, assign its signature to the proposal and send it back to the Mixin Group. When enough signatures collected, the node will aggregrate the signatures, generate the final Price Data, store it and publish it to the subscribers.

View the Proposal Handler codes.

Documentation

Overview

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
exchanges
handler
hc
pkg
aes
mtg
service
store

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL