Skip to content

Commit

Permalink
Release 3.6.3 (#928)
Browse files Browse the repository at this point in the history
### Additions

- Added a possibility to pause FT transfers for the internal eth
connector by [@karim-en]. ([#922])

[#922]: #922

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Karim <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 16, 2024
1 parent dcba953 commit 932412d
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 31 deletions.
11 changes: 10 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.6.3] 2024-04-16

### Additions

- Added a possibility to pause FT transfers for the internal eth connector by [@karim-en]. ([#922])

[#922]: https://github.com/aurora-is-near/aurora-engine/pull/922

## [3.6.2] 2024-03-27

### Additions
Expand Down Expand Up @@ -643,7 +651,8 @@ struct SubmitResult {

## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.2...develop
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.3...develop
[3.6.3]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.2...3.6.3
[3.6.2]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.1...3.6.2
[3.6.1]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.0...3.6.1
[3.6.0]: https://github.com/aurora-is-near/aurora-engine/compare/3.5.0...3.6.0
Expand Down
19 changes: 13 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.2
3.6.3
2 changes: 2 additions & 0 deletions engine-tests-connector/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub const UNPAUSE_ALL: PausedMask = 0;
pub const PAUSE_DEPOSIT: PausedMask = 1 << 0;
/// Admin control flow flag indicates that withdrawal is paused.
pub const PAUSE_WITHDRAW: PausedMask = 1 << 1;
/// Admin control flow flag indicates that ft transfers are paused.
pub const PAUSE_FT: PausedMask = 1 << 2;

pub struct TestContract {
pub engine_contract: Contract,
Expand Down
139 changes: 139 additions & 0 deletions engine-tests/src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,145 @@ pub mod workspace {
assert_eq!(result, balances);
}

#[cfg(not(feature = "ext-connector"))]
#[tokio::test]
async fn test_pause_ft_transfer() {
use aurora_engine::contract_methods::connector::internal::{PAUSE_FT, UNPAUSE_ALL};
use aurora_engine::parameters::FungibleTokenMetadata;
use aurora_engine_types::account_id::AccountId;

use crate::utils::workspace::storage_deposit_nep141;

let aurora = deploy_engine().await;
let metadata = FungibleTokenMetadata::default();
aurora
.set_eth_connector_contract_data(
aurora.id(),
ETH_CUSTODIAN_ADDRESS.to_string(),
metadata,
)
.transact()
.await
.unwrap();

deposit_balance(&aurora).await;

let recipient_id = AccountId::new("account1").unwrap();
let transfer_amount = 10;

// Pause ft transfers
aurora.set_paused_flags(PAUSE_FT).transact().await.unwrap();
// Verify that the storage deposit is paused
let result = storage_deposit_nep141(&aurora.id(), &aurora.root(), recipient_id.as_ref())
.await
.unwrap()
.into_result();
assert!(result.unwrap_err().to_string().contains("ERR_FT_PAUSED"));
// Try to transfer tokens
let result = aurora
.ft_transfer(&recipient_id, transfer_amount.into(), None)
.deposit(ONE_YOCTO)
.transact()
.await;
assert!(result.unwrap_err().to_string().contains("ERR_FT_PAUSED"));
// Verify that no tokens were transferred
let blanace = aurora.ft_balance_of(&recipient_id).await.unwrap().result;
assert_eq!(blanace.0, 0);

// Unpause ft transfers
aurora
.set_paused_flags(UNPAUSE_ALL)
.transact()
.await
.unwrap();
// Transfer tokens
aurora
.ft_transfer(&recipient_id, transfer_amount.into(), None)
.deposit(ONE_YOCTO)
.transact()
.await
.unwrap();
// Verify that the tokens has been transferred
let blanace = aurora.ft_balance_of(&recipient_id).await.unwrap().result;
assert_eq!(blanace.0, transfer_amount);
}

#[cfg(not(feature = "ext-connector"))]
#[tokio::test]
async fn test_pause_ft_transfer_call() {
use crate::utils::workspace::transfer_call_nep_141;
use aurora_engine::contract_methods::connector::internal::{PAUSE_FT, UNPAUSE_ALL};
use aurora_engine::parameters::FungibleTokenMetadata;

let aurora = deploy_engine().await;
let metadata = FungibleTokenMetadata::default();
aurora
.set_eth_connector_contract_data(
aurora.id(),
ETH_CUSTODIAN_ADDRESS.to_string(),
metadata,
)
.transact()
.await
.unwrap();

deposit_balance(&aurora).await;

let ft_owner = create_sub_account(&aurora.root(), "ft_owner", BALANCE)
.await
.unwrap();
let transfer_amount = 10;
// Transfer tokens to the `ft_owner` account
aurora
.ft_transfer(&ft_owner.id(), transfer_amount.into(), None)
.deposit(ONE_YOCTO)
.transact()
.await
.unwrap();
let blanace = aurora.ft_balance_of(&ft_owner.id()).await.unwrap().result;
assert_eq!(blanace.0, transfer_amount);

// Pause ft transfers
aurora.set_paused_flags(PAUSE_FT).transact().await.unwrap();
// Try to transfer tokens from `ft_owner` to `aurora` contract by `ft_transfer_call`
let transfer_call_msg = "000000000000000000000000000000000000dead";
let result = transfer_call_nep_141(
&aurora.id(),
&ft_owner,
aurora.id().as_ref(),
transfer_amount,
transfer_call_msg,
)
.await
.unwrap()
.into_result();
assert!(result.unwrap_err().to_string().contains("ERR_FT_PAUSED"));
let blanace = aurora.ft_balance_of(&ft_owner.id()).await.unwrap().result;
assert_eq!(blanace.0, transfer_amount);

// Unpause ft transfers
aurora
.set_paused_flags(UNPAUSE_ALL)
.transact()
.await
.unwrap();
// Transfer tokens from `ft_owner` to `aurora` contract by `ft_transfer_call`
transfer_call_nep_141(
&aurora.id(),
&ft_owner,
aurora.id().as_ref(),
transfer_amount,
transfer_call_msg,
)
.await
.unwrap()
.into_result()
.unwrap();
// Verify that the tokens has been transferred
let blanace = aurora.ft_balance_of(&ft_owner.id()).await.unwrap().result;
assert_eq!(blanace.0, 0);
}

async fn test_exit_to_near_eth_common() -> anyhow::Result<TestExitToNearEthContext> {
let aurora = deploy_engine().await;
let chain_id = aurora.get_chain_id().await?.result.as_u64();
Expand Down
41 changes: 41 additions & 0 deletions engine-tests/src/utils/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use aurora_engine_types::parameters::connector::{FungibleTokenMetadata, Withdraw
use aurora_engine_types::types::Address;
use aurora_engine_types::U256;
use aurora_engine_workspace::account::Account;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine_workspace::types::ExecutionFinalResult;
use aurora_engine_workspace::{types::NearToken, EngineContract, RawContract};
use serde_json::json;

Expand Down Expand Up @@ -236,6 +238,45 @@ pub async fn transfer_nep_141(
Ok(())
}

#[cfg(not(feature = "ext-connector"))]
pub async fn storage_deposit_nep141(
nep_141: &AccountId,
source: &Account,
dest: &str,
) -> anyhow::Result<ExecutionFinalResult> {
source
.call(nep_141, "storage_deposit")
.args_json(json!({
"account_id": dest,
}))
.deposit(STORAGE_AMOUNT)
.max_gas()
.transact()
.await
}

#[cfg(not(feature = "ext-connector"))]
pub async fn transfer_call_nep_141(
nep_141: &AccountId,
source: &Account,
dest: &str,
amount: u128,
msg: &str,
) -> anyhow::Result<ExecutionFinalResult> {
source
.call(nep_141, "ft_transfer_call")
.args_json(json!({
"receiver_id": dest,
"amount": amount.to_string(),
"memo": "null",
"msg": msg,
}))
.deposit(NearToken::from_yoctonear(1))
.max_gas()
.transact()
.await
}

#[cfg(feature = "ext-connector")]
fn get_aurora_eth_connector_contract() -> Vec<u8> {
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aurora-engine"
version = "3.6.2"
version = "3.6.3"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions engine/src/contract_methods/connector/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub enum FtTransferCallError {
MessageParseFailed(ParseOnTransferMessageError),
InsufficientAmountForFee,
Transfer(TransferError),
Paused,
}

impl From<TransferError> for FtTransferCallError {
Expand Down Expand Up @@ -118,6 +119,7 @@ impl AsRef<[u8]> for FtTransferCallError {
Self::InsufficientAmountForFee => errors::ERR_NOT_ENOUGH_BALANCE_FOR_FEE,
Self::Transfer(e) => e.as_ref(),
Self::BalanceOverflow(e) => e.as_ref(),
Self::Paused => errors::ERR_FT_PAUSED,
}
}
}
Expand Down Expand Up @@ -200,6 +202,7 @@ pub enum TransferError {
SelfTransfer,
Deposit(DepositError),
Withdraw(WithdrawError),
Paused,
}

impl AsRef<[u8]> for TransferError {
Expand All @@ -213,6 +216,7 @@ impl AsRef<[u8]> for TransferError {
Self::SelfTransfer => errors::ERR_SENDER_EQUALS_RECEIVER,
Self::Deposit(e) => e.as_ref(),
Self::Withdraw(e) => e.as_ref(),
Self::Paused => errors::ERR_FT_PAUSED,
}
}
}
Expand All @@ -239,6 +243,7 @@ pub enum StorageFundingError {
NoAvailableBalance,
InsufficientDeposit,
UnRegisterPositiveBalance,
Paused,
}

impl AsRef<[u8]> for StorageFundingError {
Expand All @@ -250,6 +255,7 @@ impl AsRef<[u8]> for StorageFundingError {
Self::UnRegisterPositiveBalance => {
errors::ERR_FAILED_UNREGISTER_ACCOUNT_POSITIVE_BALANCE
}
Self::Paused => errors::ERR_FT_PAUSED,
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions engine/src/contract_methods/connector/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub const UNPAUSE_ALL: PausedMask = 0;
pub const PAUSE_DEPOSIT: PausedMask = 1 << 0;
/// Admin control flow flag indicates that withdrawal is paused.
pub const PAUSE_WITHDRAW: PausedMask = 1 << 1;
/// Admin control flow flag indicates that ft transfers are paused.
pub const PAUSE_FT: PausedMask = 1 << 2;

#[named]
pub fn new_eth_connector<I: IO + Copy, E: Env>(io: I, env: &E) -> Result<(), ContractError> {
Expand Down Expand Up @@ -854,6 +856,9 @@ impl<I: IO + Copy> EthConnectorContract<I> {
predecessor_account_id: &AccountId,
args: &TransferCallArgs,
) -> Result<(), errors::TransferError> {
self.assert_not_paused(PAUSE_FT, false)
.map_err(|_| errors::TransferError::Paused)?;

self.ft.internal_transfer_eth_on_near(
predecessor_account_id,
&args.receiver_id,
Expand Down Expand Up @@ -904,6 +909,9 @@ impl<I: IO + Copy> EthConnectorContract<I> {
args: TransferCallCallArgs,
prepaid_gas: NearGas,
) -> Result<PromiseWithCallbackArgs, errors::FtTransferCallError> {
self.assert_not_paused(PAUSE_FT, false)
.map_err(|_| errors::FtTransferCallError::Paused)?;

sdk::log!(
"Transfer call to {} amount {}",
args.receiver_id,
Expand Down Expand Up @@ -963,6 +971,9 @@ impl<I: IO + Copy> EthConnectorContract<I> {
amount: Yocto,
args: StorageDepositCallArgs,
) -> Result<Option<PromiseBatchAction>, errors::StorageFundingError> {
self.assert_not_paused(PAUSE_FT, false)
.map_err(|_| errors::StorageFundingError::Paused)?;

let account_id = args
.account_id
.unwrap_or_else(|| predecessor_account_id.clone());
Expand All @@ -983,6 +994,9 @@ impl<I: IO + Copy> EthConnectorContract<I> {
account_id: AccountId,
force: Option<bool>,
) -> Result<Option<PromiseBatchAction>, errors::StorageFundingError> {
self.assert_not_paused(PAUSE_FT, false)
.map_err(|_| errors::StorageFundingError::Paused)?;

let promise = match self.ft.internal_storage_unregister(account_id, force) {
Ok((_, p)) => {
self.io.return_output(b"true");
Expand Down
Loading

0 comments on commit 932412d

Please sign in to comment.