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: add function to return wNEAR address #807

Merged
merged 3 commits into from
Aug 2, 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions engine-tests/src/tests/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 9 additions & 4 deletions engine-workspace/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion engine-workspace/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -181,6 +182,7 @@ pub enum View {
Erc20FromNep141,
Nep141FromErc20,
AccountsCounter,
FactoryWnearAddress,
}

impl AsRef<str> for View {
Expand Down Expand Up @@ -210,6 +212,7 @@ impl AsRef<str> 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",
}
}
}
9 changes: 9 additions & 0 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading