Skip to content

A top-level repo to house Median deploys across chains/pairs

Notifications You must be signed in to change notification settings

amusingaxl/medianite

 
 

Repository files navigation

Medianite

This repo is for managing the code for Median deploys across multiple chains, such as Ethereum, Arbitrum, Optimism, etc.

It's based on the pattern described here, and uses makerdao/median as the source template.

Effectively, it allows you to generate a Median deploy segregated by chain and pair. For instance you might need a Median contract deployed on Arbitrum (an L2) for the ETHUSD pair, and a different one for Optimism/ETHUSD, and yet another one for Arbitrum/AAVEUSD.

Getting started

Each deployed contract will be stored under the deploy folder based on the chain and pair. For example

deploy/arbitrum-ETHUSD

will contain the Median source code that is deployed to Arbitrum for the ETHUSD pair. This code should be the same whether running a local testnet, the chain's testnet (e.g. Rinkeby), or the chain's mainnet.

Prerequisites

You'll need dapptools along with a pretty normal selection of dev tools like make, git, jq, and bash.

Create a new deploy

Simply run

make new-deploy

and you will be prompted for a couple pieces of information. A deploy folder will be created and the source generated. After running the above, you can cd into the deploy folder and do the usual things, e.g.

cd deploy/arbitrum-ETHUSD/median
make build
make test
dapp create MedianETHUSD

Secrets

For testing, various Ethereum accounts have been created. They live in this repository, and are encrypted by sops.

The script ethaccounts.sh can be used to decrypt and store these accounts locally in the .testing_keystore folder, and they can be used for running integration tests via test.sh.

NOTE You will need to have access to the master (gpg) key to get access to these secrets. It's also encrypted and stored in the repo. It can be shared over secure channels. Once imported, you should be able to encrypt or decrypt any secret file stored anywhere in this repo.

Testing

The script test.sh is provided for integration tests. It uses .testing_keystore for oracles (which is generated by ethaccounts.sh above). This keystore contains 15 valid addresses that should work on any Ethereum compatible chain, including a local testnet.

After setting up the local test accounts, the only personal setup you'll need is getting an ETH_FROM account with funds on the appropriate chain.

To run the test, you will need to set some environment variables

export ETH_PASSWORD=~/path/to/file/with/ETH_FROM/password
export ETH_GAS=3000000
export ETH_RPC_URL=http://access/to/chain/like/infura
export ETH_KEYSTORE=~/path/to/ethereum/keystore
export ETH_FROM=0xDEADBEEF

As stated above, you'll be setting these variables to whatever account you need to access the contract on the appropriate chain. Once the above is done, and assuming the contract is already deployed, you can now run tests. Almost.

You need to set the bar for the contract, and also lift the oracle test accounts. As a convenience, test.sh can do this for you. After deploying the contract, run test.sh once with the following parameters to initialize the contract for testing:

MEDIAN=0x123abc PAIR=ETHUSD SET_BAR=15 ./test.sh lift-accounts

(Obviously, update PAIR and SET_BAR above to whatever is appropriate for your test.)

Now you're ready to actually test poke().

MEDIAN=0x123abc PAIR=ETHUSD ./test.sh

Walkthrough: Local testnet

Start up a local testnet, which will create an Account you can use for ETH_FROM:

dapp testnet

dapp-testnet:   RPC URL: http://127.0.0.1:8545
dapp-testnet:  TCP port: 38545
dapp-testnet:  Chain ID: 99
dapp-testnet:  Database: /Users/jar/.dapp/testnet/8545
dapp-testnet:  Geth log: /Users/jar/.dapp/testnet/8545/geth.log
dapp-testnet:   Account: 0x609a3232e1161e086d05560222D375c2621ca23e (default)

Then, from the top of this repo, set the environment variables more or less like:

export ETH_FROM=0x609a3232e1161e086d05560222D375c2621ca23e   # from dapp testnet output above
export ETH_PASSWORD=$(pwd)/template/median/empty
export ETH_GAS=3000000
export ETH_RPC_URL=http://127.0.0.1:8545
export ETH_KEYSTORE="$HOME/.dapp/testnet/8545/keystore"

Build and deploy.

pushd deploy/arbitrum-ETHUSD/median && \
	make build && \
	dapp create MedianETHUSD && \
	popd

The above command will output a contract address for the deployed median, e.g. 0x87D89A7b758dE3a1bc37E2144c30CE74D203Da22. You'll need to set (or pass) this to test.sh.

Final step, do some contract initialization, like lift()ing accounts. The accounts will be pulled from the locally generated .testing_keystore folder.

MEDIAN=0x87D89A7b758dE3a1bc37E2144c30CE74D203Da22 SET_BAR=15 PAIR=ETHUSD ./test.sh lift-accounts

Do the test.

MEDIAN=0x87D89A7b758dE3a1bc37E2144c30CE74D203Da22 PAIR=ETHUSD ./test.sh

About

A top-level repo to house Median deploys across chains/pairs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 77.7%
  • Shell 19.7%
  • Nix 1.4%
  • Makefile 1.2%