Giter Site home page Giter Site logo

alireza-gsh / moebius Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roynalnaruto/moebius

0.0 0.0 0.0 758 KB

Moebius is a cross-chain oracle that bridges on-chain Ethereum data to Solana.

License: Apache License 2.0

Shell 1.95% JavaScript 5.71% Rust 85.52% Dockerfile 0.26% Solidity 6.56%

moebius's Introduction

Moebius is a cross-chain oracle that bridges on-chain Ethereum data to Solana.

Overview

Moebius is a program deployed on Solana that accepts update instructions from the Moebius authority. The authority key is loaded in Moebius Bridge and listen for the Moebius events on the Ethereum blockchain. On noticing such an event, the authority then broadcasts an update instruction to the Moebius program deployed on Solana.

The update instruction received by Moebius then invokes an update instruction on the target program and account. The update succeeds if the target program and account follow Moebius-compatible structure, and are capable of decoding and processing the instruction.

In order to enable a cross-chain oracle via Moebius, a user will need to:

A successful execution of the above transaction would emit the event:

event MoebiusData(bytes32 _programId, bytes32 _accountId, bytes _packedData);

that the Moebius bridge is listening for.

An event with the above signature would be intercepted, parsed and broadcasted to the Moebius program deployed to Solana by a trusted Moebius authority.

Moebius-Uniswap

Using Moebius Bridge, the first use-case implemented was to bridge Uniswap time-weighted average prices (TWAP) from Ethereum contracts to Solana programs.

  • A transaction that updated the Uniswap UNI/WETH average price on Ethereum here
  • A transaction that updated the Uniswap UNI/WETH pricefeed state on Solana here

Ethereum

The below contracts are deployed on the Ethereum's Ropsten testnet

Contract Address
Moebius 0x4f2A9aC3A70400636190e1df213Fd7Aa0BCF794d
Uniswap Oracle 0x20412cA3DA74560695529C7c5D34C1e766B52AeB

Solana

The below programs are deployed on Solana's Devnet

Program/Account Address
Moebius 6kAHanNCT1LKFoMn3fBdyvJuvHLcWhLpJbTpbHpqRiG4
Uniswap Program G33TSUoKH1xM7bPXTMoQhGQhfwWkWT8dGaW6dunDQoen
Trusted Moebius Authority BREEUNEkUnR7TidwEGptGDREGD3aVHu5Qv5Bvan9fjP6
  • Run script that periodically updates and consults the Uniswap oracle. Make sure the address you use has sufficient Ropsten ETH balance.
$ cd ethereum/
# export INFURA_API_KEY=your-infura-api-key
# export ETH_PRIVATE_KEY=your-hex-private-key-excluding-0x
$ npx hardhat run scripts/update-uniswap-oracle.js --network ropsten
  • Run Moebius Reporter, a GraphQL server that exposes Uniswap pricefeed from Solana account.
$ cd solana/
$ ./target/debug/reporter

Visit http://localhost:8080/graphiql and query:

query {
    uniswapOracle(token0: "1f9840a85d5af5bf1d1762f925bdaddc4201f984", token1: "c778417e063141139fce010982780140aa0cd5ab") {
        token0
        decimal0
        amount0
        token1
        decimal1
        amount1
        priceToken0Token1
        priceToken1Token0
    }
}

where 1f9840a85d5af5bf1d1762f925bdaddc4201f984 is UNI and c778417e063141139fce010982780140aa0cd5ab is WETH. If Moebius bridge is disabled, the reporter will respond with the most recently updated pricefeed.

  • Use Moebius API to fetch Uniswap pricefeed in your Solana programs.
//
// [dependencies]
// moebius-api = { git = "https://github.com/roynalnaruto/moebius/solana/moebius-api" }
//
// Instantiate API client
let api = moebius_api::MoebiusApi::new()
    .with_rpc_url(String::from("https://devnet.solana.com"));
// Fetch UNI-WETH pricefeed
let pricefeed = api.uniswap_oracle(
    "1f9840a85d5af5bf1d1762f925bdaddc4201f984",
    "c778417e063141139fce010982780140aa0cd5ab"
)?;
// UNI/WETH
let price_token0_token1 = pricefeed.price_token0_token1();
// WETH/UNI
let price_token1_token0 = pricefeed.price_token1_token0();

Setup Guides

To setup Moebius and its components locally, follow:

moebius's People

Contributors

roynalnaruto 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.