Code Monkey home page Code Monkey logo

eth-anchor-contracts's Introduction

Anchor Ethereum Wrapping Contracts (EthAnchor)

EthAnchor is a set of Ethereum-side contracts that wrap around Anchor’s UST deposit flow to be accessible from Ethereum. It works alongside with eth-anchor-bot to forward and automate any deposits and withdrawal requests being made on Ethereum to the Terra blockchain.

Considerations

Interchain operations on Anchor are non-atomic. For example, when depositing Ethereum UST to Anchor Protocol, the following operations must be consecutively executed:

* Transfer UST from Ethereum to a specified Terra address over a token transfer bridge, such as Wormhole or Shuttle.
* `eth-anchor-bot` keeps a record of token lock events and deposit contract events on Ethereum.
* `eth-anchor-bot` runs the `deposit_stable{}` `ExecuteMsg` on the Anchor money market contracts and receives aUST.
* aUST is sent back to the original Ethereum depositor address over a token transfer bridge.

On a typical Ethereum Dapp, as all operations are atomic & transactionality is preserved, the result of a deposit operation would immediately return either:

  • transaction succeeded
  • transaction failed (for whatever reason)

after the transaction is mined. However, as Anchor’s core logic lives on the Terra blockchain and there is no state-level synchronization, there is no atomic guarantee of the outcome of the transaction. For example

  • the contract does not know whether interchain token transfers for either UST or aUST has succeeded
  • the contract does not know whether deposit_stable{} has succeeded
  • there is a possibility that eth-anchor-bot itself has failed, and the contract has no knowledge of it

thus, to handle exception cases due to this non-atomicity, the contract is configured as follows:

  • all operations are paired with separate init - finish contract calls. a caller should call init first to invoke an operation, and then call finish to finalize the operation.
  • no additional init calls can be made before an operation pair is finalized with a finish call. for example, a new initDepositStable() call cannot be made before finishDepositStable() is invoked.

Contract List

Core

Operation

Extension

Setup

deps

$ git clone https://github.com/anchor-protocol/eth-anchor-contracts

$ cd eth-anchor-contracts

$ yarn

config

  • add local.config.ts beside hardhat.config.ts with this template
export const Networks = {
  ropsten: {
    url: "https://ropsten.infura.io/v3/{api_key}",
    accounts: ["{private_key_1}", "{private_key_2}", "{private_key_3}"],
  },
  mainnet: {
    url: "https://mainnet.infura.io/v3/{api_key}",
    accounts: ["{private_key_1}", "{private_key_2}", "{private_key_3}"],
  },
};

export const EtherscanAPIKey = "{api_key}";

Commands

$ yarn compile      # compile project

$ yarn test         # test project

$ yarn coverage     # test project with coverage

$ yarn deploy-core  # deploy core contracts (Operation, Store, Factory, Router, Controller...)

$ yarn deploy-exts  # deploy extension contracts (ConversionPool, ExchangeRateFeeder...)

License

MIT

eth-anchor-contracts's People

Contributors

byeongsu-hong avatar unifiedh avatar dependabot[bot] 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.