Skip to content

Commit d86eb73

Browse files
martriayAmxxandrew-flemingericnordelo
authored
Migrate ERC721 (#619)
* continue account implementation * add missing account interface functions * tidy up module * fix validate * bump cairo + account changes * fix __execute__, add serde, rename felt>felt252 * tidy up code * WIP ERC721 * make format * fix dispatcher call * clean * working on tests * replace match with `is_some()` and `is_none()` for readeability * erc721 tests * use Option.expect * add account tests * check panic reason * rename _owner() to _owner_of() * spacing * complete account implementation * apply recommandation for PR * Apply suggestions from code review Co-authored-by: Andrew Fleming <[email protected]> * check low level ownership int * prefix test function with test_ * Apply suggestions from code review Co-authored-by: Andrew Fleming <[email protected]> Co-authored-by: Hadrien Croubois <[email protected]> * apply review suggestions * remove unused import * clarify __execute__ guard * add account tests * add internals * tidy up * update ERC165 ids to u32 * apply sugestions from code review * Apply suggestions from code review Co-authored-by: Martín Triay <[email protected]> * update & expand tests * update lock * add internal macro * add internal macro * add deregister * update erc165 * wip (dispatched issue) * fix abi * start array→span transition * minimise account dependency * add SpanSerde in utils * add dual interfaces * update test message. fix linter * split interfaces from preset module * fix linter * rename metadata id var * add camelCase to traits * fully implement dual interface traits * simplify _owner_of * add constructor and getter tests * add token_uri tests * remove conflictive test * add erc721receiver. add IERC721ABI * add safe_transfer_from tests * add safe_mint tests * Update src/openzeppelin/token/erc721/interface.cairo Co-authored-by: Eric Nordelo <[email protected]> * move erc721 abi next to module * address review comments --------- Co-authored-by: Hadrien Croubois <[email protected]> Co-authored-by: Andrew Fleming <[email protected]> Co-authored-by: Andrew Fleming <[email protected]> Co-authored-by: Eric Nordelo <[email protected]>
1 parent 372de37 commit d86eb73

File tree

11 files changed

+1414
-1
lines changed

11 files changed

+1414
-1
lines changed

src/openzeppelin/introspection/erc165.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const IERC165_ID: u32 = 0x01ffc9a7_u32;
22
const INVALID_ID: u32 = 0xffffffff_u32;
33

4+
#[abi]
45
trait IERC165 {
56
fn supports_interface(interface_id: u32) -> bool;
67
}

src/openzeppelin/tests.cairo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ mod test_ownable;
44
mod test_erc165;
55
mod test_account;
66
mod test_erc20;
7-
mod test_pausable;
7+
mod test_erc721;
88
mod test_initializable;
9+
mod test_pausable;
910
mod mocks;
1011
mod utils;

src/openzeppelin/tests/mocks.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mod reentrancy_attacker_mock;
22
mod reentrancy_mock;
3+
mod erc721_receiver;
34
mod mock_pausable;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const SUCCESS: felt252 = 123123;
2+
const FAILURE: felt252 = 456456;
3+
4+
#[contract]
5+
mod ERC721Receiver {
6+
use openzeppelin::token::erc721::interface::IERC721Receiver;
7+
use openzeppelin::token::erc721::interface::IERC721ReceiverCamel;
8+
use openzeppelin::token::erc721::interface::IERC721_RECEIVER_ID;
9+
use openzeppelin::introspection::erc165::ERC165;
10+
11+
use openzeppelin::utils::serde::SpanSerde;
12+
use starknet::ContractAddress;
13+
use array::SpanTrait;
14+
15+
impl ERC721ReceiverImpl of IERC721Receiver {
16+
fn on_erc721_received(
17+
operator: ContractAddress, from: ContractAddress, token_id: u256, data: Span<felt252>
18+
) -> u32 {
19+
if *data.at(0) == super::SUCCESS {
20+
IERC721_RECEIVER_ID
21+
} else {
22+
0
23+
}
24+
}
25+
}
26+
27+
impl ERC721ReceiverCamelImpl of IERC721ReceiverCamel {
28+
fn onERC721Received(
29+
operator: ContractAddress, from: ContractAddress, tokenId: u256, data: Span<felt252>
30+
) -> u32 {
31+
ERC721ReceiverImpl::on_erc721_received(operator, from, tokenId, data)
32+
}
33+
}
34+
35+
#[constructor]
36+
fn constructor() {
37+
ERC165::register_interface(IERC721_RECEIVER_ID);
38+
}
39+
40+
#[view]
41+
fn supports_interface(interface_id: u32) -> bool {
42+
ERC165::supports_interface(interface_id)
43+
}
44+
45+
#[external]
46+
fn on_erc721_received(
47+
operator: ContractAddress, from: ContractAddress, token_id: u256, data: Span<felt252>
48+
) -> u32 {
49+
ERC721ReceiverImpl::on_erc721_received(operator, from, token_id, data)
50+
}
51+
52+
#[external]
53+
fn onERC721Received(
54+
operator: ContractAddress, from: ContractAddress, tokenId: u256, data: Span<felt252>
55+
) -> u32 {
56+
ERC721ReceiverCamelImpl::onERC721Received(operator, from, tokenId, data)
57+
}
58+
}
59+
60+
61+
#[contract]
62+
mod ERC721NonReceiver {}

0 commit comments

Comments
 (0)