Skip to content

Commit

Permalink
feat: add support of set_eth_connector_contract_data (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss committed Mar 19, 2024
1 parent 0c3faa2 commit f5eea66
Show file tree
Hide file tree
Showing 11 changed files with 859 additions and 475 deletions.
1,154 changes: 734 additions & 420 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ name = "aurora-cli"
path = "src/main.rs"

[features]
default = [ "simple" ]
simple = []
advanced = []
default = ["simple"]
simple = ["toml"]
advanced = ["near-chain-configs"]

[dependencies]
aurora-engine-precompiles = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.1", features = ["std"] }
aurora-engine-sdk = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.1", features = ["std"] }
aurora-engine-transactions = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.1", features = ["std"] }
aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.1", features = ["std", "impl-serde"] }
aurora-engine-precompiles = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.6.1", features = ["std"] }
aurora-engine-sdk = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.6.1", features = ["std"] }
aurora-engine-transactions = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.6.1", features = ["std"] }
aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.6.1", features = ["std", "impl-serde"] }

anyhow = "1"
bs58 = "0.5"
clap = { version = "4", features = ["derive"] }
ethabi = "18"
hex = "0.4.3"
lazy_static = "1.4.0"
hex = "0.4"
lazy_static = "1"
libsecp256k1 = { version = "0.7", features = ["std"] }
near-chain-configs = "0.17"
near-crypto = "0.17"
near-jsonrpc-client = "0.6"
near-jsonrpc-primitives = "0.17"
near-primitives = "0.17"
near-chain-configs = { version = "0.20", optional = true }
near-crypto = "0.20"
near-jsonrpc-client = "0.8"
near-jsonrpc-primitives = "0.20"
near-primitives = "0.20"
reqwest = { version = "0.11", features = ["json"] }
rand = "0.8"
rlp = "0.5.0"
rlp = "0.5"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.8.10"
shadow-rs = "0.24"
toml = { version = "0.8", optional = true }
shadow-rs = "0.27"
thiserror = "1"
tokio = { version = "1", features = ["full"] }

[build-dependencies]
shadow-rs = "0.24"
shadow-rs = "0.27"
12 changes: 7 additions & 5 deletions scripts/advanced.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

EVM_CODE=$(cat docs/res/HelloWorld.hex)
ABI_PATH="docs/res/HelloWorld.abi"
AURORA_LAST_VERSION="2.9.2"
AURORA_LAST_VERSION=$(curl -s https://api.github.com/repos/aurora-is-near/aurora-engine/releases/latest | jq -r .tag_name)
ENGINE_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-mainnet.wasm"
ENGINE_WASM_PATH="/tmp/aurora-mainnet.wasm"
USER_BASE_BIN=$(python3 -m site --user-base)/bin
VENV=/tmp/venv

export PATH="$PATH:$USER_BASE_BIN:$HOME/.cargo/bin"
export NEARCORE_HOME="/tmp/localnet"

# Install `nearup` utility if not installed before.
pip3 list | grep nearup > /dev/null || pip3 install --user nearup
python3 -m venv $VENV
source $VENV/bin/activate
pip list | grep nearup > /dev/null || pip install nearup > /dev/null

start_node() {
cmd="nearup run localnet --home $NEARCORE_HOME --num-nodes 1"
Expand All @@ -27,7 +28,8 @@ finish() {
# Stop NEAR node.
nearup stop > /dev/null 2>&1
# Cleanup
rm -rf $NEARCORE_HOME
deactivate
rm -rf $NEARCORE_HOME $VENV

if [[ -z "$1" ]]; then
exit 0
Expand Down
14 changes: 8 additions & 6 deletions scripts/different-outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@

export NEARCORE_HOME="/tmp/localnet"

AURORA_PREV_VERSION="2.10.2"
AURORA_LAST_VERSION="3.1.0"
AURORA_PREV_VERSION="3.6.0"
AURORA_LAST_VERSION=$(curl -s https://api.github.com/repos/aurora-is-near/aurora-engine/releases/latest | jq -r .tag_name)
EVM_CODE=$(cat docs/res/HelloWorld.hex)
ABI_PATH="docs/res/HelloWorld.abi"
ENGINE_PREV_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_PREV_VERSION/aurora-mainnet.wasm"
ENGINE_LAST_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-mainnet.wasm"
XCC_ROUTER_LAST_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-factory-mainnet.wasm"
ENGINE_WASM_PATH="/tmp/aurora-mainnet.wasm"
XCC_ROUTER_WASM_PATH="/tmp/aurora-factory-mainnet.wasm"
USER_BASE_BIN=$(python3 -m site --user-base)/bin
NODE_KEY_PATH=$NEARCORE_HOME/node0/validator_key.json
AURORA_KEY_PATH=$NEARCORE_HOME/node0/aurora_key.json
MANAGER_KEY_PATH=$NEARCORE_HOME/node0/manager_key.json
RELAYER_KEY_PATH=$NEARCORE_HOME/node0/relayer_key.json
AURORA_SECRET_KEY=27cb3ddbd18037b38d7fb9ae3433a9d6f5cd554a4ba5768c8a15053f688ee167
ENGINE_ACCOUNT=aurora.node0
MANAGER_ACCOUNT=key-manager.aurora.node0
VENV=/tmp/venv

export PATH="$PATH:$USER_BASE_BIN:$HOME/.cargo/bin"
export PATH="$HOME/NearProtocol/aurora/aurora-cli-rs/target/debug/:$PATH:$USER_BASE_BIN"


# Install `nearup` utility if not installed before.
pip3 list | grep nearup > /dev/null || pip3 install --user nearup
python3 -m venv $VENV
source $VENV/bin/activate
pip list | grep nearup > /dev/null || pip install nearup > /dev/null

start_node() {
cmd="nearup run localnet --home $NEARCORE_HOME"
Expand All @@ -45,7 +46,8 @@ finish() {
# Stop NEAR node.
stop_node
# Cleanup
rm -rf $NEARCORE_HOME
deactivate
rm -rf $NEARCORE_HOME $VENV

if [[ -z "$1" ]]; then
exit 0
Expand Down
10 changes: 6 additions & 4 deletions scripts/simple-silo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ export NEARCORE_HOME="/tmp/localnet"
EVM_CODE=$(cat docs/res/Counter.hex)
ABI_PATH=docs/res/Counter.abi
ENGINE_WASM_PATH="docs/res/aurora-mainnet-silo.wasm"
USER_BASE_BIN=$(python3 -m site --user-base)/bin
NODE_KEY_PATH=$NEARCORE_HOME/node0/validator_key.json
AURORA_KEY_PATH=$NEARCORE_HOME/node0/aurora_key.json
AURORA_SECRET_KEY=27cb3ddbd18037b38d7fb9ae3433a9d6f5cd554a4ba5768c8a15053f688ee167
ENGINE_ACCOUNT=aurora.node0
VENV=/tmp/venv

export PATH="$PATH:$USER_BASE_BIN:$HOME/.cargo/bin"

# Install `nearup` utility if not installed before.
pip3 list | grep nearup > /dev/null || pip3 install --user nearup
python3 -m venv $VENV
source $VENV/bin/activate
pip list | grep nearup > /dev/null || pip install nearup > /dev/null

start_node() {
cmd="nearup run localnet --home $NEARCORE_HOME"
Expand All @@ -34,7 +35,8 @@ finish() {
# Stop NEAR node.
stop_node
# Cleanup
rm -rf $NEARCORE_HOME
deactivate
rm -rf $NEARCORE_HOME $VENV

if [[ -z "$1" ]]; then
exit 0
Expand Down
21 changes: 14 additions & 7 deletions scripts/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@

export NEARCORE_HOME="/tmp/localnet"

AURORA_PREV_VERSION="2.10.2"
AURORA_LAST_VERSION="3.1.0"
AURORA_PREV_VERSION="3.6.0"
AURORA_LAST_VERSION=$(curl -s https://api.github.com/repos/aurora-is-near/aurora-engine/releases/latest | jq -r .tag_name)
EVM_CODE=$(cat docs/res/HelloWorld.hex)
ABI_PATH="docs/res/HelloWorld.abi"
ENGINE_PREV_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_PREV_VERSION/aurora-mainnet.wasm"
ENGINE_LAST_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-mainnet.wasm"
XCC_ROUTER_LAST_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-factory-mainnet.wasm"
ENGINE_WASM_PATH="/tmp/aurora-mainnet.wasm"
XCC_ROUTER_WASM_PATH="/tmp/aurora-factory-mainnet.wasm"
USER_BASE_BIN=$(python3 -m site --user-base)/bin
NODE_KEY_PATH=$NEARCORE_HOME/node0/validator_key.json
AURORA_KEY_PATH=$NEARCORE_HOME/node0/aurora_key.json
MANAGER_KEY_PATH=$NEARCORE_HOME/node0/manager_key.json
RELAYER_KEY_PATH=$NEARCORE_HOME/node0/relayer_key.json
AURORA_SECRET_KEY=27cb3ddbd18037b38d7fb9ae3433a9d6f5cd554a4ba5768c8a15053f688ee167
ENGINE_ACCOUNT=aurora.node0
MANAGER_ACCOUNT=key-manager.aurora.node0
VENV=/tmp/venv

export PATH="$PATH:$USER_BASE_BIN:$HOME/.cargo/bin"
export PATH="$HOME/NearProtocol/aurora/aurora-cli-rs/target/debug/:$PATH:$USER_BASE_BIN"


# Install `nearup` utility if not installed before.
pip3 list | grep nearup > /dev/null || pip3 install --user nearup
python3 -m venv $VENV
source $VENV/bin/activate
pip list | grep nearup > /dev/null || pip install nearup > /dev/null

start_node() {
cmd="nearup run localnet --home $NEARCORE_HOME"
Expand All @@ -45,7 +46,8 @@ finish() {
# Stop NEAR node.
stop_node
# Cleanup
rm -rf $NEARCORE_HOME
deactivate
rm -rf $NEARCORE_HOME $VENV

if [[ -z "$1" ]]; then
exit 0
Expand Down Expand Up @@ -95,7 +97,7 @@ aurora-cli --engine $ENGINE_ACCOUNT init \
--ft-metadata-path docs/res/ft_metadata.json || error_exit
sleep 2

# Upgrading Aurora EVM to 2.10.0.
# Upgrading Aurora EVM to the latest.
version=$(aurora-cli --engine $ENGINE_ACCOUNT get-version || error_exit)
assert_eq "$version" $AURORA_PREV_VERSION
echo "$version"
Expand All @@ -108,6 +110,11 @@ version=$(aurora-cli --engine $ENGINE_ACCOUNT get-version || error_exit)
assert_eq "$version" $AURORA_LAST_VERSION
echo "$version"

# Modify eth connector data
aurora-cli --engine $ENGINE_ACCOUNT set-eth-connector-contract-data --prover-id "another.prover" \
--custodian-address "0xa3078bf607d2e859dca0b1a13878ec2e607f30de" --ft-metadata-path docs/res/ft_metadata.json || error_exit
sleep 1

# Create account id for key manager
aurora-cli create-account --account $MANAGER_ACCOUNT --balance 10 > $MANAGER_KEY_PATH || error_exit
sleep 1
Expand Down
4 changes: 2 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub use advanced::{run, Cli};
pub use simple::{command, run, Cli};

/// NEAR Endpoints.
const NEAR_MAINNET_ENDPOINT: &str = "https://archival-rpc.mainnet.near.org/";
const NEAR_TESTNET_ENDPOINT: &str = "https://archival-rpc.testnet.near.org/";
const NEAR_MAINNET_ENDPOINT: &str = "https://rpc.mainnet.near.org/";
const NEAR_TESTNET_ENDPOINT: &str = "https://rpc.testnet.near.org/";
#[cfg(feature = "simple")]
const NEAR_LOCAL_ENDPOINT: &str = "http://127.0.0.1:3030/";
/// Aurora Endpoints.
Expand Down
34 changes: 32 additions & 2 deletions src/cli/simple/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,31 @@ pub async fn set_eth_connector_account_id(
.await
}

/// Set internal ETH connector data (prover id, custodian address and FT metadata).
pub async fn set_eth_connector_contract_data<P: AsRef<Path> + Send>(
context: Context,
prover_id: String,
custodian_address: String,
ft_metadata_path: P,
) -> anyhow::Result<()> {
let args = InitCallArgs {
prover_account: prover_id.parse().map_err(|e| anyhow::anyhow!("{e}"))?,
eth_custodian_address: custodian_address.trim_start_matches("0x").to_string(),
metadata: utils::ft_metadata::parse_ft_metadata(
std::fs::read_to_string(ft_metadata_path).ok(),
)?,
}
.try_to_vec()?;

contract_call!(
"set_eth_connector_contract_data",
"ETH connector data has been set successfully",
"Error while setting ETH connector data"
)
.proceed(context, args)
.await
}

async fn get_value<T: FromCallResult + Display>(
context: Context,
method_name: &str,
Expand Down Expand Up @@ -846,8 +871,13 @@ impl ContractCall<'_> {
FinalExecutionStatus::Failure(e) => {
anyhow::bail!("{}: {e}", self.error_message)
}
FinalExecutionStatus::SuccessValue(_) => match context.output_format {
OutputFormat::Plain => println!("{}", self.success_message),
FinalExecutionStatus::SuccessValue(output) => match context.output_format {
// TODO: The output could be serialized with JSON or Borsh.
// TODO: In the case of Borsh we should provide a type for deserializing the output in the corresponding object.
OutputFormat::Plain => match to_string_pretty(&output) {
Ok(msg) if !output.is_empty() => println!("{}\n{msg}", self.success_message),
Ok(_) | Err(_) => println!("{}", self.success_message),
},
OutputFormat::Json => {
let formatted = to_string_pretty(&result.transaction_outcome)?;
println!("{formatted}");
Expand Down
25 changes: 25 additions & 0 deletions src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,18 @@ pub enum Command {
#[arg(long)]
withdraw_ser: Option<WithdrawSerialization>,
},
/// Set eth connector data
SetEthConnectorContractData {
/// Prover account id
#[arg(long)]
prover_id: String,
/// Custodian ETH address
#[arg(long)]
custodian_address: String,
/// Path to the file with the metadata of the fungible token
#[arg(long)]
ft_metadata_path: String,
},
}

#[derive(Clone)]
Expand Down Expand Up @@ -575,6 +587,19 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
} => {
command::set_eth_connector_account_id(context, account_id, withdraw_ser).await?;
}
Command::SetEthConnectorContractData {
prover_id,
custodian_address,
ft_metadata_path,
} => {
command::set_eth_connector_contract_data(
context,
prover_id,
custodian_address,
ft_metadata_path,
)
.await?;
}
}

Ok(())
Expand Down
Loading

0 comments on commit f5eea66

Please sign in to comment.