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

feat: added new upgrade and factory_get_wnear_address transactions #51

Merged
merged 1 commit into from
Dec 6, 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
33 changes: 23 additions & 10 deletions src/cli/simple/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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::borsh::{BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::connector::{
Erc20Identifier, Erc20Metadata, InitCallArgs, MirrorErc20TokenArgs, SetErc20MetadataArgs,
SetEthConnectorContractAccountArgs, WithdrawSerializeType,
Expand All @@ -13,6 +13,7 @@ use aurora_engine_types::parameters::engine::{
RelayerKeyManagerArgs, SetOwnerArgs, SetUpgradeDelayBlocksArgs, SubmitResult,
TransactionStatus,
};
use aurora_engine_types::parameters::xcc::FundXccArgs;
use aurora_engine_types::public_key::{KeyType, PublicKey};
use aurora_engine_types::types::Address;
use aurora_engine_types::{types::Wei, H256, U256};
Expand Down Expand Up @@ -202,8 +203,9 @@ pub async fn deploy_evm_code(
let result = SubmitResult::try_from_slice(bytes)?;
if let TransactionStatus::Succeed(bytes) = result.status {
format!(
"Contract has been deployed to address: 0x{} successfully",
hex::encode(bytes)
"Contract has been deployed to address: 0x{} successfully, gas used: {}",
hex::encode(bytes),
result.gas_used,
)
} else {
format!("Transaction reverted: {result:?}")
Expand Down Expand Up @@ -328,6 +330,19 @@ pub async fn call(
Ok(())
}

/// Upgrade Aurora Contract with provided code.
pub async fn upgrade<P: AsRef<Path> + Send>(client: Client, path: P) -> anyhow::Result<()> {
let code = std::fs::read(path)?;

contract_call!(
"upgrade",
"The aurora contract has been upgraded successfully",
"Error while upgrading the aurora smart contract"
)
.proceed(client, code)
.await
}

/// Stage code for delayed upgrade.
pub async fn stage_upgrade<P: AsRef<Path> + Send>(client: Client, path: P) -> anyhow::Result<()> {
let code = std::fs::read(path)?;
Expand Down Expand Up @@ -365,6 +380,11 @@ pub async fn factory_update(client: Client, path: String) -> anyhow::Result<()>
.await
}

/// Returns the address of the `wNEAR` ERC-20 contract
pub async fn factory_get_wnear_address(client: Client) -> anyhow::Result<()> {
get_value::<HexString>(client, "factory_get_wnear_address", None).await
}

/// Sets the address for the `wNEAR` ERC-20 contract
pub async fn factory_set_wnear_address(client: Client, address: String) -> anyhow::Result<()> {
let args: [u8; 20] = hex_to_arr(&address)?;
Expand All @@ -378,13 +398,6 @@ pub async fn factory_set_wnear_address(client: Client, address: String) -> anyho
.await
}

// TODO: Use it from aurora_engine_types::parameters::xcc module.
#[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize)]
struct FundXccArgs {
pub target: Address,
pub wnear_account_id: Option<AccountId>,
}

/// Create and/or fund an XCC sub-account directly
pub async fn fund_xcc_sub_account(
client: Client,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub enum Command {
PausedPrecompiles,
/// Updates the bytecode for user's router contracts
FactoryUpdate { path: String },
/// Return the address of the `wNEAR` ERC-20 contract
FactoryGetWnearAddress,
/// Sets the address for the `wNEAR` ERC-20 contract
FactorySetWnearAddress { address: String },
/// Create and/or fund an XCC sub-account directly
Expand All @@ -127,6 +129,8 @@ pub enum Command {
/// Attached deposit in NEAR
deposit: f64,
},
/// Upgrade contract with provided code
Upgrade { path: String },
/// Stage a new code for upgrade
StageUpgrade { path: String },
/// Deploy staged upgrade
Expand Down Expand Up @@ -417,6 +421,7 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
Command::PausedPrecompiles => command::paused_precompiles(client).await?,
Command::GetUpgradeIndex => command::get_upgrade_index(client).await?,
Command::FactoryUpdate { path } => command::factory_update(client, path).await?,
Command::FactoryGetWnearAddress => command::factory_get_wnear_address(client).await?,
Command::FactorySetWnearAddress { address } => {
command::factory_set_wnear_address(client, address).await?;
}
Expand All @@ -427,6 +432,7 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
} => {
command::fund_xcc_sub_account(client, target, wnear_account_id, deposit).await?;
}
Command::Upgrade { path } => command::upgrade(client, path).await?,
Command::StageUpgrade { path } => command::stage_upgrade(client, path).await?,
Command::DeployUpgrade => command::deploy_upgrade(client).await?,
Command::GetStorageAt { address, key } => {
Expand Down
Loading