Skip to content
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: 2 additions & 0 deletions integration/src/erc721_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,14 @@ impl Erc721Collection {
&self,
caller: &mut dyn ContractCaller,
from: Address,
to: Address,
token_id: u64,
) -> Result<Vec<ContractLog>> {
self.send(
caller,
ierc721::forcedTransferCall {
from,
to,
tokenId: U256::from(token_id),
},
)
Expand Down
4 changes: 3 additions & 1 deletion integration/tests/revive_erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ async fn erc721_forced_transfer() -> Result<()> {
assert_eq!(nft.owner_of(1).await?, holder_address);

// The agent takes it back.
let logs = nft.forced_transfer(&mut caller, holder_address, 1).await?;
let logs = nft
.forced_transfer(&mut caller, holder_address, owner_address, 1)
.await?;
let events: Vec<ierc721::ForcedTransfer> = decode_contract_logs(&logs, &nft.h160())?;
assert_eq!(events.len(), 1, "expected one ForcedTransfer event");
assert_eq!(events[0].from, holder_address);
Expand Down
14 changes: 8 additions & 6 deletions pallets/precompiles/src/interface/nft/erc7943.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use pallet_revive::precompiles::{Error, Ext};
use pallet_asset::WeightInfo;
use pallet_nft::WeightInfo as NFTWeightInfo;
use polymesh_precompiles::{INonFungibleAsset, INonFungibleAssetEvents};
use polymesh_primitives::asset::{AssetHolderKind, AssetId};
use polymesh_primitives::asset::AssetId;
use polymesh_primitives::nft::NFTs;
use polymesh_primitives::WeightMeter;

Expand Down Expand Up @@ -67,9 +67,10 @@ impl<T: Config> NonFungibleAssetInterface<T> {
))
}

/// Takes `tokenId` from `from` and transfers it to the caller's account key.
/// Takes `tokenId` from `from` and transfers it to `to`.
///
/// Bypasses compliance and frozen checks; the caller must be an agent of the collection.
/// Only an asset holder account is supported as the destination for now.
pub(crate) fn forced_transfer(
asset_id: AssetId,
call: &INonFungibleAsset::forcedTransferCall,
Expand All @@ -78,23 +79,24 @@ impl<T: Config> NonFungibleAssetInterface<T> {
let caller = Common::<T>::caller(env)?;
let nft_id = Self::nft_id(call.tokenId)?;
let source = Common::<T>::asset_holder(env, call.from)?;
let destination = Common::<T>::asset_holder(env, call.to)?;
let nfts = NFTs::new_unverified(asset_id, vec![nft_id]);

Common::<T>::call_runtime(
env,
caller.runtime_origin(),
pallet_nft::Call::<T>::controller_transfer {
pallet_nft::Call::<T>::controller_transfer_to {
nfts,
source,
destination_kind: AssetHolderKind::Account,
destination,
},
)?;

Common::<T>::deposit_event(
env,
INonFungibleAssetEvents::ForcedTransfer(INonFungibleAsset::ForcedTransfer {
from: call.from,
to: caller.address.0.into(),
to: call.to,
tokenId: call.tokenId,
}),
)?;
Expand All @@ -103,7 +105,7 @@ impl<T: Config> NonFungibleAssetInterface<T> {
env,
INonFungibleAssetEvents::Transfer(INonFungibleAsset::Transfer {
from: call.from,
to: caller.address.0.into(),
to: call.to,
tokenId: call.tokenId,
}),
)?;
Expand Down
Binary file modified precompiles/src/interfaces/NonFungibleAssetStub.bin
Binary file not shown.
7 changes: 4 additions & 3 deletions precompiles/src/interfaces/NonFungibleAssetStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ interface INonFungibleAsset {
/// @dev Returns true if `tokenId` can currently be transferred from `from` to `to`.
function canTransfer(address from, address to, uint256 tokenId) external view returns (bool);

/// @dev Forcibly transfers `tokenId` from `from` to the caller, bypassing compliance and
/// @dev Forcibly transfers `tokenId` from `from` to `to`, bypassing compliance and
/// frozen checks. The caller must be an agent of the collection.
///
/// Emits {ForcedTransfer} and {Transfer} events.
function forcedTransfer(address from, uint256 tokenId) external returns (bool);
function forcedTransfer(address from, address to, uint256 tokenId) external returns (bool);
Comment thread
Neopallium marked this conversation as resolved.

/// @dev Returns true if `account` is currently allowed to send tokens of this collection.
function canSend(address account) external view returns (bool);
Expand Down Expand Up @@ -291,8 +291,9 @@ contract NonFungibleAssetStub is INonFungibleAsset {
revert NotExecutable();
}

function forcedTransfer(address from, uint256 tokenId) external override returns (bool) {
function forcedTransfer(address from, address to, uint256 tokenId) external override returns (bool) {
from;
to;
tokenId;
revert NotExecutable();
}
Expand Down