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

Complete Aurora CLI Engine methods #2

Merged
merged 22 commits into from
Dec 23, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.DS_Store
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aurora-engine = { git = "https://github.com/aurora-is-near/aurora-engine.git", t
aurora-engine-precompiles = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "2.7.0", features = ["std"] }
aurora-engine-sdk = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "2.7.0", features = ["std"] }
aurora-engine-transactions = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "2.7.0", features = ["std"] }
aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "2.7.0", features = ["std"] }
aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "2.7.0", features = ["std", "serde"] }
base64 = "0.13.0"
borsh = "0.9.3"
bs58 = "0.4.0"
Expand Down
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# `aurora-cli-rs`
<p>&nbsp;</p>
<p align="center">
<img src="https://raw.githubusercontent.com/hskang9/aurora-cli-rs/main/img/aurora-cli-logo.png" width=500>
</p>

A command-line interface for interacting with [Aurora](https://aurora.dev/).
<p align="center">
<strong>An instant, zero-config Aurora engine operator</strong>
</p>

See also prior art [aurora-cli](https://github.com/aurora-is-near/aurora-cli).
<br/>

## What is Engine?

[Aurora](https://doc.aurora.dev/getting-started/aurora-engine/) is an Ethereum Virtual Machine (EVM) project built on the NEAR Protocol, that provides a solution for developers to deploy their apps on an Ethereum-compatible, high-throughput, scalable and future-safe platform, with low transaction costs for their users. Engine is the Aurora's implementation for it.

## What is Aurora CLI?
Aurora CLI is a command line interface to bootstrap Aurora engine with rapid speed built with rust.

Aurora CLI comes preconfiguration with opinionated, sensible defaults for standard testing environments. If other projects mention testing on Aurora, they are referring to the settings defined in this repo.

**Aurora CLI has the following advantages over api:**

- :pencil: **Easily modifiable EVM states through terminal**
- :handshake: **Quick to interact for rapid iterations**

See also prior version [aurora-cli](https://github.com/aurora-is-near/aurora-cli).

## Prerequisites
- :crab: Rust

## Quickstart

- 📦 Install `aurora-cli-rs` and start interacting with it:
*`cargo install --git https://github.com/aurora-is-near/aurora-cli-rs.git`*
- 🔍 Check out what each command is for in the official Aurora [docs](https://doc.aurora.dev/tools/aurora-cli)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting dependency on aurora-is-near/doc.aurora.dev#78
These PRs should be merged together so that the link here is not broken.

- ✋ Have questions? Ask them at the official Aurora [forum](https://forum.aurora.dev/)
Binary file added img/aurora-cli-logo-blck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/aurora-cli-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion src/cli/aurora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub async fn execute_command<T: AsRef<str>>(
config: &Config,
) -> Result<(), Box<dyn std::error::Error>> {
match command {
// Command::Benchmark
Command::Read { subcommand } => match subcommand {
ReadCommand::GetResult { tx_hash_hex } => {
let tx_hash =
Expand Down Expand Up @@ -113,7 +114,6 @@ async fn send_transaction<T: AsRef<str>>(

let nonce = client.get_nonce(source).await?;
let chain_id = client.get_chain_id().await?;

let tx_hash = client
.eth_transaction(to, amount, sk, chain_id, nonce, input)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ pub enum Command {
action: process_tx_data::ProcessTxAction,
input_files_list_path: String,
},
}
}
hskang9 marked this conversation as resolved.
Show resolved Hide resolved
188 changes: 184 additions & 4 deletions src/cli/near.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use crate::{client::AuroraClient, config::Config, utils};
use std::str::FromStr;

use crate::{
client::AuroraClient,
config::Config,
utils,
};
use aurora_engine::parameters::{DeployErc20TokenArgs, GetStorageAtArgs, PauseEthConnectorCallArgs};
use aurora_engine_types::{
parameters::{CrossContractCallArgs, PromiseArgs, PromiseCreateArgs},
types::{Address, NearGas, Wei, Yocto},
U256,
U256, account_id::AccountId,
};
use borsh::BorshSerialize;
use clap::Subcommand;
Expand Down Expand Up @@ -70,13 +77,41 @@ pub enum ReadCommand {
#[clap(subcommand)]
contract_call: crate::cli::solidity::Solidity,
},
// get nep141_from_erc20
GetBridgedNep141 {
erc_20_address_hex: String,
},
GetAuroraErc20 {
nep_141_account: String,
},
GetEngineBridgeProver,
// get_chain_id
GetChainId,
// get_upgrade_index
GetUpgradeIndex,
// get_block_hash
GetBlockHash {
block_number: String,
},
// get_code
GetCode {
address_hex: String,
},
// get_balance
GetBalance {
address_hex: String,
},
// get_nonce
GetNonce {
address_hex: String,
},
// get_storage_at
GetStorageAt {
address_hex: String,
key_hex: String,
},
// get_paused_flags
GetPausedFlags,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -122,6 +157,27 @@ pub enum WriteCommand {
FactoryUpdate {
wasm_bytes_path: String,
},
// deploy_code
DeployCode {
code_byte_hex: String,
},
// register_relayer
RegisterRelayer {
relayer_eth_address_hex: String,
},
// deploy_erc20_token
DeployERC20Token {
nep141: String,
},
// deposit
Deposit {
raw_proof: String,
}, // storage_deposit
// set_paused_flags
SetPausedFlags {
paused_mask: String,
},

}

pub async fn execute_command<T: AsRef<str>>(
Expand Down Expand Up @@ -227,11 +283,90 @@ pub async fn execute_command<T: AsRef<str>>(
};
}
ReadCommand::GetAuroraErc20 { nep_141_account } => {
println!("{:?}", client.get_erc20_from_nep141(&nep_141_account).await);
println!("{:?}", client.get_erc20_from_nep141(&nep_141_account).await?);
}
ReadCommand::GetEngineBridgeProver => {
println!("{:?}", client.get_bridge_prover().await);
println!("{:?}", client.get_bridge_prover().await?);
}
ReadCommand::GetChainId => {
let chain_id = {
let result = client.near_view_call("get_chain_id".into(), vec![]).await?;
U256::from_big_endian(&result.result).low_u64()
};
println!("{:?}", chain_id);
}
ReadCommand::GetUpgradeIndex => {
let upgrade_index = {
let result = client
.near_view_call("get_upgrade_index".into(), vec![])
.await?;
U256::from_big_endian(&result.result).low_u64()
};
println!("{:?}", upgrade_index);
}
ReadCommand::GetBlockHash {
block_number
} => {
let height_serialized: u128 = block_number.parse::<u128>().unwrap();
let block_hash = {
let result = client
.near_view_call("get_block_hash".into(), height_serialized.to_le_bytes().to_vec())
.await?.result;
result
};
println!("{:?}", hex::encode(block_hash));
}
ReadCommand::GetCode { address_hex } => {
let code = client
.near_view_call("get_code".into(), address_hex.as_bytes().to_vec())
.await?
.result;
println!("{:?}", code);
}
ReadCommand::GetBalance { address_hex } => {
let balance = {
let result = client
.near_view_call("get_balance".into(), address_hex.as_bytes().to_vec())
.await?;
U256::from_big_endian(&result.result).low_u64()
};
println!("{:?}", balance);
}
ReadCommand::GetNonce { address_hex } => {
let nonce = {
let result = client
.near_view_call("get_nonce".into(), address_hex.as_bytes().to_vec())
.await?;
U256::from_big_endian(&result.result).low_u64()
};
println!("{:?}", nonce);
}
ReadCommand::GetStorageAt {
address_hex,
key_hex,
} => {
let mut buffer: Vec<u8> = Vec::new();
let key_bytes32: [u8;32] = hex::decode(key_hex).unwrap().try_into().unwrap();
hskang9 marked this conversation as resolved.
Show resolved Hide resolved
let input = GetStorageAtArgs {
address: Address::decode(&address_hex).unwrap(),
key: key_bytes32,
};
input.serialize(&mut buffer)?;
let storage = {
let result = client
.near_view_call("get_storage_at".into(), buffer)
.await?;
hex::encode(result.result)
};
println!("{:?}", storage);
}
ReadCommand::GetPausedFlags => {
let paused_flags = client
.near_view_call("get_paused_flags".into(), vec![])
.await?
.result;
println!("{:?}", paused_flags);
}
},
Command::Write { subcommand } => match subcommand {
WriteCommand::EngineXcc {
Expand Down Expand Up @@ -305,6 +440,51 @@ pub async fn execute_command<T: AsRef<str>>(
.unwrap();
println!("{:?}", tx_outcome);
}
WriteCommand::DeployCode { code_byte_hex } => {
let input = hex::decode(code_byte_hex)?;
let tx_outcome = client
.near_contract_call("deploy_code".into(), input)
.await?;
println!("{:?}", tx_outcome);
}
WriteCommand::RegisterRelayer {
relayer_eth_address_hex,
} => {
let relayer = hex::decode(relayer_eth_address_hex)?;
let tx_outcome = client
.near_contract_call("register_relayer".into(), relayer)
.await?;
println!("{:?}", tx_outcome);
}
WriteCommand::DeployERC20Token { nep141 } => {
let mut buffer: Vec<u8> = Vec::new();
let nep141: AccountId = nep141.parse().unwrap();
let input = DeployErc20TokenArgs {
nep141
};
input.serialize(&mut buffer)?;
let tx_outcome = client
.near_contract_call("deploy_erc20_token".into(), buffer)
.await?;
println!("{:?}", tx_outcome);
}
WriteCommand::Deposit { raw_proof } => {
let tx_outcome = client
.near_contract_call("deposit".into(), raw_proof.as_bytes().to_vec())
.await?;
println!("{:?}", tx_outcome);
},
WriteCommand::SetPausedFlags { paused_mask } => {
let mut buffer: Vec<u8> = Vec::new();
let input = PauseEthConnectorCallArgs {
paused_mask: u8::from_str(&paused_mask).unwrap(),
};
input.serialize(&mut buffer)?;
let tx_outcome = client
.near_contract_call("set_paused_flags".into(), buffer)
.await?;
println!("{:?}", tx_outcome);
},
},
};
Ok(())
Expand Down