# Smart Contracts

The Morpher Protocol consists of six main smart contracts and several auxiliary contracts that are deployed both on Ethereum and the Morpher sidechain.

  • MorpherToken: the basic ERC20 token functionality (transfer token, approve transfer, token balance, etc.).
  • MorpherState: the smart contract that contains the eternal storage of the Protocol (i.e. all balances, trades, and stakes).
  • MorpherOracle: an oracle smart contract.
  • MorpherTradeEngine: a smart contract that computes the state transitions (staking/unstaking/minting/burning).
  • MorpherGovernance: a smart contract that allows for on-chain governance of the Protocol.
  • MorpherBridge: a smart contract that allows the side chain operator to write the root hash of a Merkle tree containing the complete state of the side chain to the main chain.

The Sidechain is linked with Ethereum by updating its merkelized state on Ethereum in periodic intervals (Ethereum Plasma scaling approach), see MorpherBridge.

# MorpherToken

Sidechain

0xC44628734a9432a3DAA302E11AfbdFa8361424A5
View on Morpher Scan

Mainchain

0x6369c3DadfC00054A42BA8B2c09c48131dd4Aa38
View on Etherscan

The MorpherToken contract provides the ERC20 token functionality for Morpher’s MPH token. It is based on the ERC20 token from OpenZeppelin. Kudos to OpenZeppelin for their contributions to the development of the Ethereum ecosystem!

MPH token cannot be transferred between accounts on the sidechain. MPH token can be burned by their owner on both chains.

# MorpherState

Sidechain

0xB4881186b9E52F8BD6EC5F19708450cE57b24370
View on Morpher Scan

Mainchain

0x1f426C51F0Ef7655A6f4c3Eb58017d2F1c381bfF
View on Etherscan

MorpherState is the eternal storage of the Morpher Protocol. Anyone can read from MorpherState, but only explicitly whitelisted addresses are eligible to write. MorpherState saves token balances, Virtual Futures, and relevant protocol addresses and roles. The protocol is designed to be upgradable via separation of storage and logic. MorpherState contains the protocol storage, and the other contracts containing the logic link to MorpherState and can be upgraded to newer versions without losing the protocol state.

# MorpherOracle

Sidechain

0x434C8915D68f98F956A6Fd5d7e0cA6a2b6516590
View on Morpher Scan

Mainchain

0x3CBC7e439FD0A98182622136d38EBa03Aac17A72
View on Etherscan

Via the MorpherOracle contract, users can create and close Virtual Futures. The Oracle records the user’s orders for creating or closing Virtual Futures and fires an associated event that is read by the Oracle Operator. The Operator requests the latest market data for an order from a trusted source and signs a callback function to write the market data on the blockchain, where the order is subsequently processed by MorpherTradeEngine.

# MorpherTradeEngine

Sidechain

0x9de9773A77a9b51330736E73429622CC32F51926
View on Morpher Scan

Mainchain

0xB4881186b9E52F8BD6EC5F19708450cE57b24370
View on Etherscan

MorpherTradeEngine computes transitions between MPH token and Virtual Futures. Upon creation of a Virtual Future, MorpherTradeEngine calculates how many units the Virtual Future consists of, its liquidation price, and creates it in MorpherState. Upon closing a Virtual Future, MorpherTradeEngine calculates its current value in MPH token, mints the MPH token, and deletes the Virtual Future from MorpherState.

# MorpherGovernance

Mainchain

0x9de9773a77a9b51330736e73429622cc32f51926
View on Etherscan

MorpherGovernance lets protocol validators vote on the MorpherOracle and the protocol Administrator. To become a validator, it is required to lock MPH token in the MorpherGovernance contract. The first validator locks 10m MPH token, the second validator 20m MPH token, and so forth. It becomes progressively harder to operate a validator. When stepping down, validators receive 99% of their staked token back, while 1% is burned. Voting for MorpherOracle allows a simple majority of validators to replace the protocol oracle with another smart contract. By voting for the administrator, a simple majority of validators can also replace the Protocol Administrator address.

# MorpherBridge

Mainchain

0xC44628734a9432a3DAA302E11AfbdFa8361424A5
View on Etherscan

MorpherBridge moves token between the Sidechain and Ethereum mainchain. Token can be transferred by burning them on one chain and claiming them on the other. Both chains track the number of destroyed/claimed token on both chains. All positions and balances of the sidechain are merkelized, and the root hash of the Merkle Tree is written to Ethereum in periodic intervals (initially: 1 hour). Users can use the root hash to prove the existence of their positions on sidechain. This allows full recovery of positions on Ethereum if the sidechain ceases to operate for over 72 hours.

# Administrator Role

Sidechain

0x32deB065F8f4863BAc2c0a8931aAE8Ae46a88E67
View on Morpher Scan

Mainchain (temporary)

0x082Bc2c3697f6E84A876613A2bde873D904e0256
View on Etherscan

The Administrator of the Morpher Protocol is an account that can be voted for by MorpherGovernance. The Administrator has the power to enable/disable markets for trading, to set the maximum allowed leverage, and to pause token transfers.

# Security and Audits

Several security audits have been performed on the Morpher Protocol before the smart contracts were deployed to production on June 4, 2020. The smart contracts were thoroughly examined for their robustness against known exploits like contract reentrancy (dForce and TheDAO hack) and the delegatecall exploit (Parity Multisig) by third-party auditors. The most recent audit was done by Capacity.at.