From a21a79bebc702529ba0d2c3319cb734e6dc00080 Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Wed, 6 Dec 2023 19:25:59 +0000 Subject: [PATCH] feat: added new upgrade and factory_get_wnear_address transactions (#51) --- src/cli/simple/command/mod.rs | 33 +++++++++++++++++++++++---------- src/cli/simple/mod.rs | 6 ++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/cli/simple/command/mod.rs b/src/cli/simple/command/mod.rs index 3062dfc..a8203a6 100644 --- a/src/cli/simple/command/mod.rs +++ b/src/cli/simple/command/mod.rs @@ -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, @@ -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}; @@ -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:?}") @@ -328,6 +330,19 @@ pub async fn call( Ok(()) } +/// Upgrade Aurora Contract with provided code. +pub async fn upgrade + 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 + Send>(client: Client, path: P) -> anyhow::Result<()> { let code = std::fs::read(path)?; @@ -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::(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)?; @@ -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, -} - /// Create and/or fund an XCC sub-account directly pub async fn fund_xcc_sub_account( client: Client, diff --git a/src/cli/simple/mod.rs b/src/cli/simple/mod.rs index ec7d8ed..70247f4 100644 --- a/src/cli/simple/mod.rs +++ b/src/cli/simple/mod.rs @@ -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 @@ -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 @@ -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?; } @@ -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 } => {