diff --git a/Cargo.lock b/Cargo.lock index b0aa133..6a5e73b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,7 +257,7 @@ dependencies = [ [[package]] name = "aurora-engine-modexp" version = "1.0.0" -source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.0#1aad2a057ab3bb5cb10ffac3a9ffa09ee64bfba3" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.1#99634869db649e865a67d588024700fe0dcc80b0" dependencies = [ "hex", "num", @@ -266,7 +266,7 @@ dependencies = [ [[package]] name = "aurora-engine-precompiles" version = "1.0.0" -source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.0#1aad2a057ab3bb5cb10ffac3a9ffa09ee64bfba3" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.1#99634869db649e865a67d588024700fe0dcc80b0" dependencies = [ "aurora-engine-modexp", "aurora-engine-sdk", @@ -285,7 +285,7 @@ dependencies = [ [[package]] name = "aurora-engine-sdk" version = "1.0.0" -source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.0#1aad2a057ab3bb5cb10ffac3a9ffa09ee64bfba3" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.1#99634869db649e865a67d588024700fe0dcc80b0" dependencies = [ "aurora-engine-types", "base64 0.21.5", @@ -296,7 +296,7 @@ dependencies = [ [[package]] name = "aurora-engine-transactions" version = "1.0.0" -source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.0#1aad2a057ab3bb5cb10ffac3a9ffa09ee64bfba3" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.1#99634869db649e865a67d588024700fe0dcc80b0" dependencies = [ "aurora-engine-precompiles", "aurora-engine-sdk", @@ -308,7 +308,7 @@ dependencies = [ [[package]] name = "aurora-engine-types" version = "1.0.0" -source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.0#1aad2a057ab3bb5cb10ffac3a9ffa09ee64bfba3" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.3.1#99634869db649e865a67d588024700fe0dcc80b0" dependencies = [ "base64 0.21.5", "borsh 0.10.3", diff --git a/Cargo.toml b/Cargo.toml index 351585a..1136d31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,10 @@ simple = [] advanced = [] [dependencies] -aurora-engine-precompiles = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.0", features = ["std"] } -aurora-engine-sdk = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.0", features = ["std"] } -aurora-engine-transactions = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.0", features = ["std"] } -aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.3.0", features = ["std", "impl-serde"] } +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"] } anyhow = "1" bs58 = "0.5" diff --git a/README.md b/README.md index f526dc3..b6e92e7 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,15 @@ Example JSON batch file (`batch_list.json`): - [`aurora-cli add-entry-to-whitelist`](#aurora-cli-add-entry-to-whitelist) - [`aurora-cli add-entry-to-whitelist-batch`](#aurora-cli-add-entry-to-whitelist-batch) - [`aurora-cli remove-entry-from-whitelist`](#aurora-cli-remove-entry-from-whitelist) - +- [`aurora-cli set-key-manager`](#aurora-cli-set-key-manager) +- [`aurora-cli add-relayer-key`](#aurora-cli-add-relayer-key) +- [`aurora-cli remove-relayer-key`](#aurora-cli-remove-relayer-key) +- [`aurora-cli get-upgrade-delay-blocks`](#aurora-cli-get-upgrade-delay-blocks) +- [`aurora-cli set-upgrade-delay-blocks`](#aurora-cli-set-upgrade-delay-blocks) +- [`aurora-cli get-erc20-from-nep141`](#aurora-cli-get-erc20-from-nep141) +- [`aurora-cli get-nep141-from-erc20`](#aurora-cli-get-nep141-from-erc20) +- [`aurora-cli get-erc20-metadata`](#aurora-cli-get-erc20-metadata) +- [`aurora-cli set-erc20-metadata`](#aurora-cli-set-erc20-metadata) ### `aurora-cli help` @@ -331,6 +339,15 @@ Commands: add-entry-to-whitelist Add entry into the whitelist add-entry-to-whitelist-batch Add entries into the whitelist remove-entry-from-whitelist Remove the entry from the whitelist + set-key-manager Set relayer key manager + add-relayer-key Add relayer public key + remove-relayer-key Remove relayer public key + get-upgrade-delay-blocks Get delay for upgrade in blocks + set-upgrade-delay-blocks Set delay for upgrade in blocks + get-erc20-from-nep141 Get ERC-20 from NEP-141 + get-nep141-from-erc20 Get NEP-141 from ERC-20 + get-erc20-metadata Get ERC-20 metadata + set-erc20-metadata Set ERC-20 metadata help Print this message or the help of the given subcommand(s) Options: @@ -849,3 +866,134 @@ Options: -h, --help Print help ``` +### `aurora-cli set-key-manager` + +```console +$ aurora-cli help set-key-manager +Set relayer key manager + +Usage: aurora-cli set-key-manager [ACCOUNT_ID] + +Arguments: + [ACCOUNT_ID] AccountId of the key manager + +Options: + -h, --help Print help +``` + +### `aurora-cli add-relayer-key` + +```console +$ aurora-cli help add-relayer-key +Add relayer public key + +Usage: aurora-cli add-relayer-key --public-key --allowance + +Options: + --public-key Public key + --allowance Allowance + -h, --help Print help +``` + +### `aurora-cli remove-relayer-key` + +```console +$ aurora-cli help remove-relayer-key +Remove relayer public key + +Usage: aurora-cli remove-relayer-key + +Arguments: + Public key + +Options: + -h, --help Print help +``` + +### `aurora-cli get-upgrade-delay-blocks` + +```console +$ aurora-cli help get-upgrade-delay-blocks +Get delay for upgrade in blocks + +Usage: aurora-cli get-upgrade-delay-blocks + +Options: +-h, --help Print help +``` + +### `aurora-cli set-upgrade-delay-blocks` + +```console +$ aurora-cli help set-upgrade-delay-blocks +Set delay for upgrade in blocks + +Usage: aurora-cli set-upgrade-delay-blocks + +Arguments: + Number blocks + +Options: + -h, --help Print help +``` + +### `aurora-cli get-erc20-from-nep141` + +```console +$ aurora-cli help get-erc20-from-nep141 +Get ERC-20 from NEP-141 + +Usage: aurora-cli get-erc20-from-nep141 + +Arguments: + Account id of NEP-141 + +Options: + -h, --help Print help +``` + +### `aurora-cli get-nep141-from-erc20` + +```console +$ aurora-cli help get-nep141-from-erc20 +Get NEP-141 from ERC-20 + +Usage: aurora-cli get-nep141-from-erc20
+ +Arguments: +
Address for ERC-20 + +Options: + -h, --help Print help +``` + +### `aurora-cli get-erc20-metadata` + +```console +$ aurora-cli help get-erc20-metadata +Get ERC-20 metadata + +Usage: aurora-cli get-erc20-metadata + +Arguments: + Address or account id of the ERC-20 contract + +Options: + -h, --help Print help +``` + +### `aurora-cli set-erc20-metadata` + +```console +$ aurora-cli help set-erc20-metadata +Set ERC-20 metadata + +Usage: aurora-cli set-erc20-metadata --erc20-id --name --symbol --decimals + +Options: + --erc20-id Address or account id of the ERC-20 contract + --name Name of the token + --symbol Symbol of the token + --decimals Decimals of the token + -h, --help Print help +``` diff --git a/src/cli/simple/command/mod.rs b/src/cli/simple/command/mod.rs index 488f45b..e71d913 100644 --- a/src/cli/simple/command/mod.rs +++ b/src/cli/simple/command/mod.rs @@ -1,7 +1,12 @@ +use std::fmt::{Display, Formatter}; +use std::{path::Path, str::FromStr}; + use aurora_engine_sdk::types::near_account_to_evm_address; use aurora_engine_types::account_id::AccountId; use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize}; -use aurora_engine_types::parameters::connector::InitCallArgs; +use aurora_engine_types::parameters::connector::{ + Erc20Identifier, Erc20Metadata, InitCallArgs, SetErc20MetadataArgs, +}; use aurora_engine_types::parameters::engine::{ GetStorageAtArgs, NewCallArgs, NewCallArgsV2, PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs, SetOwnerArgs, SetUpgradeDelayBlocksArgs, SubmitResult, @@ -12,8 +17,6 @@ use aurora_engine_types::types::Address; use aurora_engine_types::{types::Wei, H256, U256}; use near_primitives::views::{CallResult, FinalExecutionStatus}; use serde_json::Value; -use std::fmt::{Display, Formatter}; -use std::{path::Path, str::FromStr}; use crate::{ client::Client, @@ -578,6 +581,58 @@ pub async fn set_upgrade_delay_blocks(client: Client, blocks: u64) -> anyhow::Re .await } +/// Get ERC-20 address from account id of NEP-141. +pub async fn get_erc20_from_nep141(client: Client, account_id: String) -> anyhow::Result<()> { + let args = account_id.try_to_vec()?; + get_value::(client, "get_erc20_from_nep141", Some(args)).await +} + +/// Get NEP-141 account id from address of ERC-20. +pub async fn get_nep141_from_erc20(client: Client, address: String) -> anyhow::Result<()> { + let args = hex_to_address(&address)?.as_bytes().to_vec(); + get_value::(client, "get_nep141_from_erc20", Some(args)).await +} + +/// Get a metadata of ERC-20 contract. +pub async fn get_erc20_metadata(client: Client, identifier: String) -> anyhow::Result<()> { + let args = str_to_identifier(&identifier) + .and_then(|id| serde_json::to_vec(&id).map_err(Into::into))?; + let result = client.near().view_call("get_erc20_metadata", args).await?; + let output = serde_json::from_slice::(&result.result) + .and_then(|metadata| serde_json::to_string_pretty(&metadata))?; + + println!("{output}"); + + Ok(()) +} + +/// Set a metadata of ERC-20 contract. +pub async fn set_erc20_metadata( + client: Client, + identifier: String, + name: String, + symbol: String, + decimals: u8, +) -> anyhow::Result<()> { + let erc20_identifier = str_to_identifier(&identifier)?; + let args = serde_json::to_vec(&SetErc20MetadataArgs { + erc20_identifier, + metadata: Erc20Metadata { + name, + symbol, + decimals, + }, + })?; + + contract_call!( + "set_erc20_metadata", + "ERC-20 metadata has been set successfully", + "Error while setting ERC-20 metadata" + ) + .proceed(client, args) + .await +} + async fn get_value( client: Client, method_name: &str, @@ -607,6 +662,14 @@ fn to_account_id(id: Option, client: &Client) -> anyhow::Result anyhow::Result { + hex_to_address(id).map(Into::into).or_else(|_| { + id.parse::() + .map(Into::into) + .map_err(|e| anyhow::anyhow!("{e}")) + }) +} + struct HexString(String); trait FromCallResult { @@ -656,6 +719,12 @@ impl FromCallResult for HexString { } } +impl FromCallResult for AccountId { + fn from_result(result: CallResult) -> anyhow::Result { + Self::try_from(result.result).map_err(|e| anyhow::anyhow!("{e}")) + } +} + impl Display for HexString { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "0x{}", self.0) diff --git a/src/cli/simple/mod.rs b/src/cli/simple/mod.rs index 6ad5f63..87e3576 100644 --- a/src/cli/simple/mod.rs +++ b/src/cli/simple/mod.rs @@ -1,9 +1,10 @@ +use std::str::FromStr; + use aurora_engine_types::account_id::AccountId; use aurora_engine_types::public_key::{KeyType, PublicKey}; use clap::{Parser, Subcommand}; use lazy_static::lazy_static; use shadow_rs::shadow; -use std::str::FromStr; pub mod command; @@ -279,6 +280,36 @@ pub enum Command { /// Number blocks blocks: u64, }, + /// Get ERC-20 from NEP-141 + GetErc20FromNep141 { + /// Account id of NEP-141 + account_id: String, + }, + /// Get NEP-141 from ERC-20 + GetNep141FromErc20 { + /// Address for ERC-20 + address: String, + }, + /// Get ERC-20 metadata + GetErc20Metadata { + /// Address or account id of the ERC-20 contract + erc20_id: String, + }, + /// Set ERC-20 metadata + SetErc20Metadata { + /// Address or account id of the ERC-20 contract + #[arg(long)] + erc20_id: String, + /// Name of the token + #[arg(long)] + name: String, + /// Symbol of the token + #[arg(long)] + symbol: String, + /// Decimals of the token + #[arg(long)] + decimals: u8, + }, } #[derive(Clone)] @@ -448,6 +479,23 @@ pub async fn run(args: Cli) -> anyhow::Result<()> { Command::SetUpgradeDelayBlocks { blocks } => { command::set_upgrade_delay_blocks(client, blocks).await?; } + Command::GetErc20FromNep141 { account_id } => { + command::get_erc20_from_nep141(client, account_id).await?; + } + Command::GetNep141FromErc20 { address } => { + command::get_nep141_from_erc20(client, address).await?; + } + Command::GetErc20Metadata { erc20_id } => { + command::get_erc20_metadata(client, erc20_id).await?; + } + Command::SetErc20Metadata { + erc20_id, + name, + symbol, + decimals, + } => { + command::set_erc20_metadata(client, erc20_id, name, symbol, decimals).await?; + } } Ok(())