Skip to content

omni-network/xstake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XStake

Cross-chain staking, built with Omni.

This repository is meant as an example. It demonstrates how to accept ERC20 deposits chains on multiple chains, and maintain global accounting on Omni.

These contracts are unaudited, and should not be used in production.

How it works

The protocol has two contracts

The first accepts deposits, and pays out withdrawals. The second maintains global accounting, and authorizes withdrawals. To learn how each contract works, read the source code. It's not long, and is commented generously. Read in the following order:

  1. XStaker.stake

    Entrypoint for staking. This function accepts deposits, and records them with the XStakeController via xcall.

  2. XStakeController.recordStake

    Records stake. Only callable by a known XStaker contract on a supported chain.

  3. XStakeController.unstake

    Entrypoint for unstaking. This function authorizes withdrawals, and directs a payout to the corresponding XStaker via xcall.

  4. XStaker.withdraw

    Withdraws stake back to the user. Only callable by the XStakeController.

Testing

This example includes example solidity tests . They make use of Omni's MockPortal utility to test cross chain interactions.

Run tests with

make test

Try it out

To try out the contracts, you can deploy them to a local Omni devnet.

make devnet-start
make devnet-deploy

This deploys an XStakeController to Omni's devnet EVM. Along with an XStaker to each mock rollup - mock arb and mock op. It also deploys an ERC20 staking token to each rollup. This token has a public mint() method, so you can mint tokens to test with.