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

Allow deposit from non-token owner #102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions contracts/root/TokenPredicates/ERC721Predicate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ contract ERC721Predicate is ITokenPredicate, AccessControlMixin, Initializable,
override
only(MANAGER_ROLE)
{
IRootERC721 token = IRootERC721(rootToken);
// deposit single
if (depositData.length == 32) {
uint256 tokenId = abi.decode(depositData, (uint256));
emit LockedERC721(depositor, depositReceiver, rootToken, tokenId);
IERC721(rootToken).safeTransferFrom(depositor, address(this), tokenId);

token.safeTransferFrom(token.ownerOf(tokenId), address(this), tokenId);
// deposit batch
} else {
uint256[] memory tokenIds = abi.decode(depositData, (uint256[]));
emit LockedERC721Batch(depositor, depositReceiver, rootToken, tokenIds);
uint256 length = tokenIds.length;
require(length <= BATCH_LIMIT, "ERC721Predicate: EXCEEDS_BATCH_LIMIT");
for (uint256 i; i < length; i++) {
IERC721(rootToken).safeTransferFrom(depositor, address(this), tokenIds[i]);
token.safeTransferFrom(token.ownerOf(tokenIds[i]), address(this), tokenIds[i]);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions contracts/root/TokenPredicates/MintableERC721Predicate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial
override
only(MANAGER_ROLE)
{
IMintableERC721 token = IMintableERC721(rootToken);

// Locking single ERC721 token
if (depositData.length == 32) {
Expand All @@ -103,7 +104,7 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial

// Transferring token to this address, which will be
// released when attempted to be unlocked
IMintableERC721(rootToken).safeTransferFrom(depositor, address(this), tokenId);
token.safeTransferFrom(token.ownerOf(tokenId), address(this), tokenId);

} else {
// Locking a set a ERC721 token(s)
Expand All @@ -123,7 +124,7 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial
// to this predicate address
for (uint256 i; i < length; i++) {

IMintableERC721(rootToken).safeTransferFrom(depositor, address(this), tokenIds[i]);
token.safeTransferFrom(token.ownerOf(tokenIds[i]), address(this), tokenIds[i]);

}

Expand Down
12 changes: 12 additions & 0 deletions test/predicates/ERC721Predicate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract('ERC721Predicate', (accounts) => {
const tokenId = mockValues.numbers[2]
const depositReceiver = mockValues.addresses[7]
const depositor = accounts[1]
const depositor2 = accounts[2];
let dummyERC721
let erc721Predicate
let lockTokensTx
Expand Down Expand Up @@ -88,6 +89,17 @@ contract('ERC721Predicate', (accounts) => {
const owner = await dummyERC721.ownerOf(tokenId)
owner.should.equal(erc721Predicate.address)
})

it('Should be able to receive lockTokens tx from address that does not own a token', async () => {
const depositData = abi.encode(['uint256'], [tokenId])
lockTokensTx = await erc721Predicate.lockTokens(
depositor2,
depositReceiver,
dummyERC721.address,
depositData,
)
should.exist(lockTokensTx)
})
})

describe('batch lockTokens', () => {
Expand Down
12 changes: 12 additions & 0 deletions test/predicates/MintableERC721Predicate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract('MintableERC721Predicate', (accounts) => {
const tokenId = mockValues.numbers[2]
const depositReceiver = mockValues.addresses[7]
const depositor = accounts[1]
const depositor2 = accounts[2];
let dummyMintableERC721
let mintableERC721Predicate
let lockTokensTx
Expand Down Expand Up @@ -98,6 +99,17 @@ contract('MintableERC721Predicate', (accounts) => {
const owner = await dummyMintableERC721.ownerOf(tokenId)
owner.should.equal(mintableERC721Predicate.address)
})

it('Should be able to receive lockTokens tx from address that does not own a token', async () => {
const depositData = abi.encode(['uint256'], [tokenId])
lockTokensTx = await mintableERC721Predicate.lockTokens(
depositor2,
depositReceiver,
dummyMintableERC721.address,
depositData,
)
should.exist(lockTokensTx)
})
})

describe('lockTokens called by non manager', () => {
Expand Down