Anchor-Protocol / eth-anchor-contracts

Ethereum-side wrapper contracts for Anchor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Ethereum-side wrapper contracts for Anchor

License:MIT License


Languages

Language:Solidity 49.8%Language:TypeScript 49.2%Language:JavaScript 0.9%