Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renovate Moonbase Local demo code #46

Merged
merged 15 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Run the program to schedule automation and wait for cross-chain execution
npm run rocstar
```

## Moonbase Auto-restake Demo
## Moonbeam EVM smart contract automation
### Pre-requisites
| Chain | Version | Commit hash |
| :--- | :----: | ---: |
Expand All @@ -288,57 +288,50 @@ npm run rocstar
| Moonbeam | [runtime-2201](https://github.com/PureStake/moonbeam/releases/tag/runtime-2201) | [483f51e](https://github.com/PureStake/moonbeam/commit/483f51e8c2574732c97634c20345433a74c93fd5) |
### Steps
#### Local dev environment
1. Launch OAK-blockchain, Rococo and Moonbase.
The local environment of Moonbeam is named Moonbase Local in its chain config.

Launch zombie in OAK-blockchain project root with Moonbase and Turing.
1. Launch Rococo Local, Turing Dev and Moonbase Local with zombienet. The zombienet config file is located at [OAK-blockchain repo](https://github.com/OAK-Foundation/OAK-blockchain/blob/master/zombienets/turing/moonbase.toml). Assuming you are at OAK-blockchain’s root folder, run the below command to spin up the networks.

```
zombie spawn zombienets/turing/moonbase.toml
zombienet spawn zombienets/turing/moonbase.toml
```

1. Deploy the smart contract to Moonbase.

Please configure your wallet private key to the secrets.json file in the root directory.

2. Run this program to schedule automation and wait for cross-chain execution
```
{
"privateKey": "YOUR-WALLET-PRIVATE-KEY-HERE"
}
npm run moonbase
```

Run the command below to deploy the contract.
3. The above step outlines the process of XCM automation with Moonbase Local. Upon completing the program, an 'ethereum.executed' event from Moonbase Local will be emitted. However, the event will exit with an EvmCoreErrorExitReason, which occurs because a smart contract has not been deployed yet. To successfully demonstrate smart contract automation, please follow the subsequent steps to set up a test smart contract.

```
cd src/moonbeam/contracts
# Install dependencies
npm install
# Compile smart contract
npx hardhat compile
# Deploy smart contract to Moonbase
npx hardhat run scripts/deploy.js
cd ../../..
```
The default sudo wallet of Moonbase Local Alith is used to deploy a smart contract. Run the below commands to deploy a smart contract to Moonbase Local.

1. Run the program to schedule automation and wait for cross-chain execution
```
npm run moonbase
```
```
cd src/moonbeam/contracts
npm install
npx hardhat compile # Compile smart contract
npx hardhat run scripts/deploy.js # Deploy smart contract to Moonbase
```

#### Moonbase alpha environment
1. Place seed.json(for Turing) and seed-eth.json(for Moonbase) in 'private' folder.
The commands, if successful, will print out the newly deployed smart contract. Take the Incrementer contract’s Ethereum address, and set the value to CONTRACT_ADDRESS in the beginning of src/moonbeam/moonbase-local.js. You do not need to change the value CONTRACT_INPUT;
```
Incrementer deployed to: 0x711F8F079b0BB4D16bd8C5D049358d31a1694755
```

The seed.json file is exported from the polkadot.js browser plugin.
#### Moonbase Alpha environment
The default staging environment of Moonbeam is Moonbase Alpha, since Moonbeam doesn’t have a parachain set up on Rococo.

The seed-eth.json file is downloaded after adding an account in the polkdot.js apps page of Moonbase.
1. First, we will need to set up wallets for the transactions in this demo.
1. Assuming you have a wallet created and imported to both Turing Moonbase and Moonbase Alpha’s polkadot.js dashboard.
2. Export a json file from Turing Moonbase‘s dashboard, name it `seed.json` and place it in the ./private folder.
3. Export a json file from Moonbase Alpha’s dashboard, name it `seed-eth.json` and place it in the ./private folder. Please note that the account exported should be an Ethereum account.

How to add Moonbase alpha account:
https://docs.moonbeam.network/tokens/connect/polkadotjs/
> How to add a polkadot account to Moonbase Alpha: https://docs.moonbeam.network/tokens/connect/polkadotjs/

1. Make sure you have 25 TUR in Turing for the reserved fee required to add the proxy and the execution fee for automationTime.
1. Make sure your wallet is topped up with 25 TUR on Turing Moonbase for fees required to set up a proxy wallet and task execution.

1. Make sure you have 5 DEV in Moonbase, we will transfer some to Turing's proxy account and pay the execution fee.
2. Make sure your wallet is topped up with 5 DEV on Moonbase Alpha for fees required to set up a proxy wallet and execute task scheduling.

1. Run the program to schedule automation and wait for cross-chain execution
3. Run the below command to kick off the demo. The <PASS_PHRASE> is your password to unlock the wallet on Turing Moonbase, and the <PASS_PHRASE_ETH> is your password to unlock the ethereum wallet on Moonbase Alpha.
```
PASS_PHRASE=<PASS_PHRASE> PASS_PHRASE_ETH=<PASS_PHRASE_ETH> npm run moonbase-alpha
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"rocstar": "dotenv -e .env babel-node src/astar/rocstar.js",
"shiden": "dotenv -e .env babel-node src/astar/shiden.js",
"moonbase-alpha": "dotenv -e .env babel-node src/moonbeam/moonbase-alpha.js",
"moonbase": "dotenv -e .env babel-node src/moonbeam/moonbase.js",
"moonbase-local": "dotenv -e .env babel-node src/moonbeam/moonbase-local.js",
"test-moonbase-contract": "dotenv -e .env babel-node src/moonbeam/test-moonbase-contract/index.js",
"utils": "dotenv -e .env babel-node src/utils.js",
"lint": "eslint --fix src/*"
Expand Down
4 changes: 2 additions & 2 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Shibuya from './shibuya';
import Rocstar from './rocstar';
import Shiden from './shiden';

import MoonbaseDev from './moonbase-dev';
import MoonbaseLocal from './moonbase-local';
import MoonbaseAlpha from './moonbase-alpha';

import TuringDev from './turing-dev';
Expand All @@ -22,5 +22,5 @@ export {
MangataDev, MangataRococo, Mangata,
TuringDev, Turing, TuringStaging, TuringMoonbase,
Shibuya, Rocstar, Shiden,
MoonbaseDev, MoonbaseAlpha,
MoonbaseLocal, MoonbaseAlpha,
};
8 changes: 4 additions & 4 deletions src/config/moonbase-dev.js → src/config/moonbase-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ const assets = [
id: '0',
chainId: 0,
decimals: 18,
name: 'Moonbase Development Token',
name: 'Moonbase Local Token',
symbol: 'UNIT',
address: '',
},
];

const Config = {
name: 'Moonbase Development',
key: 'moonbase-dev',
name: 'Moonbase Local',
key: 'moonbase-local',
endpoint: 'ws://127.0.0.1:9949',
relayChain: 'rococo',
relayChain: 'rococo-local',
paraId: 1000,
ss58: 1287,
assets,
Expand Down
6 changes: 3 additions & 3 deletions src/config/turing-moonbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const assets = [
];

const Config = {
name: 'Turing Moonbase Alpha',
key: 'turing-moonbase-alpha',
name: 'Turing Moonbase',
key: 'turing-moonbase',
endpoint: 'ws://167.99.226.24:8846',
relayChain: 'rococo',
relayChain: 'moonbase-relay-testnet',
paraId: 2114,
ss58: 51,
assets,
Expand Down
1 change: 0 additions & 1 deletion src/moonbeam/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
secrets.json
coverage
coverage.json
typechain
Expand Down
14 changes: 4 additions & 10 deletions src/moonbeam/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ This is the Ethereum smart contracts for testing.
Read about:
https://docs.moonbeam.network/builders/build/eth-api/dev-env/hardhat/

## Configuration

Please configure your private key to the secrets.json file in the root directory.

```
{
"privateKey": "YOUR-PRIVATE-KEY-HERE"
}
```

## Deploy

The default sudo wallet of Moonbase Local Alith is used to deploy a smart contract. Run the below commands to deploy a smart contract to Moonbase Local.

```
npm install
npx hardhat compile
npx hardhat run scripts/deploy.js
```

The commands, if successful, will print out the newly deployed smart contract. Take the Incrementer contract’s Ethereum address, and set the value to CONTRACT_ADDRESS in the beginning of src/moonbeam/moonbase-local.js. You do not need to change the value CONTRACT_INPUT;
8 changes: 4 additions & 4 deletions src/moonbeam/contracts/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 1. Import the Ethers plugin required to interact with the contract
// Import the Ethers plugin required to interact with the contract
require('@nomiclabs/hardhat-ethers');

// 2. Import your private key from your pre-funded Moonbase Alpha testing account
const { privateKey } = require('./secrets.json');
// Alith’s private key. Alith is one of the default sudo wallet on Moonbase Local.
const PRIVATE_KEY = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';

module.exports = {
solidity: '0.8.18',
networks: {
'moonbase-local': {
url: 'http://127.0.0.1:9949',
chainId: 1280,
accounts: [privateKey],
accounts: [PRIVATE_KEY],
},
},
defaultNetwork: 'moonbase-local',
Expand Down
Loading