diff --git a/Cargo.lock b/Cargo.lock index 9a04f3a1e..2da00ddbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,7 +327,7 @@ dependencies = [ [[package]] name = "aurora-engine" -version = "2.10.0" +version = "2.10.1" dependencies = [ "aurora-engine-modexp", "aurora-engine-precompiles", diff --git a/engine-tests/src/tests/xcc.rs b/engine-tests/src/tests/xcc.rs index 382312179..9b6f9e5de 100644 --- a/engine-tests/src/tests/xcc.rs +++ b/engine-tests/src/tests/xcc.rs @@ -763,6 +763,9 @@ mod workspace { .await?; assert!(result.is_success()); + let wnear_address = aurora.factory_get_wnear_address().await.unwrap().result; + assert_eq!(wnear_address, wnear_erc20.0.address); + let approve_tx = wnear_erc20.approve( cross_contract_call::ADDRESS, WNEAR_AMOUNT.into(), diff --git a/engine-workspace/src/contract.rs b/engine-workspace/src/contract.rs index 000ba8531..f7fe70551 100644 --- a/engine-workspace/src/contract.rs +++ b/engine-workspace/src/contract.rs @@ -9,10 +9,11 @@ use crate::operation::{ CallSetKeyManager, CallSetPausedFlags, CallStageUpgrade, CallStateMigration, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, CallSubmit, CallWithdraw, ViewAccountsCounter, ViewBalance, ViewBlockHash, ViewBridgeProver, ViewChainId, ViewCode, - ViewErc20FromNep141, ViewFtBalanceOf, ViewFtBalanceOfEth, ViewFtMetadata, - ViewFtTotalEthSupplyOnAurora, ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply, ViewIsUsedProof, - ViewNep141FromErc20, ViewNonce, ViewOwner, ViewPausedFlags, ViewPausedPrecompiles, - ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex, ViewVersion, ViewView, + ViewErc20FromNep141, ViewFactoryWnearAddress, ViewFtBalanceOf, ViewFtBalanceOfEth, + ViewFtMetadata, ViewFtTotalEthSupplyOnAurora, ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply, + ViewIsUsedProof, ViewNep141FromErc20, ViewNonce, ViewOwner, ViewPausedFlags, + ViewPausedPrecompiles, ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex, ViewVersion, + ViewView, }; use crate::transaction::{CallTransaction, ViewTransaction}; use aurora_engine_types::account_id::AccountId; @@ -390,6 +391,10 @@ impl EngineContract { pub fn get_accounts_counter(&self) -> ViewAccountsCounter { ViewAccountsCounter::view(&self.contract) } + + pub fn factory_get_wnear_address(&self) -> ViewFactoryWnearAddress { + ViewFactoryWnearAddress::view(&self.contract) + } } #[derive(Debug, Clone)] diff --git a/engine-workspace/src/operation.rs b/engine-workspace/src/operation.rs index 0a084694f..02507935a 100644 --- a/engine-workspace/src/operation.rs +++ b/engine-workspace/src/operation.rs @@ -78,7 +78,8 @@ impl_view_return![ (ViewErc20FromNep141 => Address, View::Erc20FromNep141, borsh), (ViewNep141FromErc20 => AccountId, View::Nep141FromErc20, borsh), (ViewPausedFlags => u8, View::PausedFlags, borsh), - (ViewAccountsCounter => u64, View::AccountsCounter, borsh) + (ViewAccountsCounter => u64, View::AccountsCounter, borsh), + (ViewFactoryWnearAddress => Address, View::FactoryWnearAddress, borsh) ]; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -181,6 +182,7 @@ pub enum View { Erc20FromNep141, Nep141FromErc20, AccountsCounter, + FactoryWnearAddress, } impl AsRef for View { @@ -210,6 +212,7 @@ impl AsRef for View { View::Erc20FromNep141 => "get_erc20_from_nep141", View::Nep141FromErc20 => "get_nep141_from_erc20", View::AccountsCounter => "get_accounts_counter", + View::FactoryWnearAddress => "factory_get_wnear_address", } } } diff --git a/engine/src/lib.rs b/engine/src/lib.rs index 3f3d4b044..3f18a40be 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -498,6 +498,15 @@ mod contract { crate::xcc::set_wnear_address(&mut io, &Address::from_array(address)); } + /// Returns the address for the `wNEAR` ERC-20 contract in borsh format. + #[no_mangle] + pub extern "C" fn factory_get_wnear_address() { + let mut io = Runtime; + let address = aurora_engine_precompiles::xcc::state::get_wnear_address(&io); + let bytes = address.try_to_vec().sdk_expect(errors::ERR_SERIALIZE); + io.return_output(&bytes); + } + /// Create and/or fund an XCC sub-account directly (as opposed to having one be automatically /// created via the XCC precompile in the EVM). The purpose of this method is to enable /// XCC on engine instances where wrapped NEAR (WNEAR) is not bridged.