From 95de4ca2cbc21e73e94b0daedfb5ec915e6913ee Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 29 Aug 2023 11:49:00 -0400 Subject: [PATCH 01/10] update selectors --- .../accesscontrol/dual_accesscontrol.cairo | 15 ++++----- src/access/ownable/dual_ownable.cairo | 11 +++---- src/account/dual_account.cairo | 13 ++++---- src/introspection/dual_src5.cairo | 5 ++- src/token/erc20/dual20.cairo | 19 +++++------ src/token/erc721/dual721.cairo | 33 +++++++++---------- src/token/erc721/dual721_receiver.cairo | 5 ++- 7 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/access/accesscontrol/dual_accesscontrol.cairo b/src/access/accesscontrol/dual_accesscontrol.cairo index eb086840e..8bd7cbc91 100644 --- a/src/access/accesscontrol/dual_accesscontrol.cairo +++ b/src/access/accesscontrol/dual_accesscontrol.cairo @@ -5,7 +5,6 @@ use array::ArrayTrait; use openzeppelin::utils::Felt252TryIntoBool; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -32,7 +31,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selectors::has_role, selectors::hasRole, args.span() + *self.contract_address, selector!("has_role"), selector!("hasRole"), args.span() ) .unwrap_and_cast() } @@ -42,7 +41,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(role); try_selector_with_fallback( - *self.contract_address, selectors::get_role_admin, selectors::getRoleAdmin, args.span() + *self.contract_address, selector!("get_role_admin"), selector!("getRoleAdmin"), args.span() ) .unwrap_and_cast() } @@ -53,7 +52,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selectors::grant_role, selectors::grantRole, args.span() + *self.contract_address, selector!("grant_role"), selector!("grantRole"), args.span() ) .unwrap_syscall(); } @@ -64,7 +63,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selectors::revoke_role, selectors::revokeRole, args.span() + *self.contract_address, selector!("revoke_role"), selector!("revokeRole"), args.span() ) .unwrap_syscall(); } @@ -75,7 +74,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selectors::renounce_role, selectors::renounceRole, args.span() + *self.contract_address, selector!("renounce_role"), selector!("renounceRole"), args.span() ) .unwrap_syscall(); } @@ -86,8 +85,8 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { try_selector_with_fallback( *self.contract_address, - selectors::supports_interface, - selectors::supportsInterface, + selector!("supports_interface"), + selector!("supportsInterface"), args.span() ) .unwrap_and_cast() diff --git a/src/access/ownable/dual_ownable.cairo b/src/access/ownable/dual_ownable.cairo index 03d2ba51b..670bb0924 100644 --- a/src/access/ownable/dual_ownable.cairo +++ b/src/access/ownable/dual_ownable.cairo @@ -7,7 +7,6 @@ use core::result::ResultTrait; use openzeppelin::utils::Felt252TryIntoBool; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use option::OptionTrait; @@ -32,7 +31,7 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { fn owner(self: @DualCaseOwnable) -> ContractAddress { let args = ArrayTrait::new(); - call_contract_syscall(*self.contract_address, selectors::owner, args.span()) + call_contract_syscall(*self.contract_address, selector!("owner"), args.span()) .unwrap_and_cast() } @@ -42,8 +41,8 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { try_selector_with_fallback( *self.contract_address, - selectors::transfer_ownership, - selectors::transferOwnership, + selector!("transfer_ownership"), + selector!("transferOwnership"), args.span() ) .unwrap_syscall(); @@ -54,8 +53,8 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { try_selector_with_fallback( *self.contract_address, - selectors::renounce_ownership, - selectors::renounceOwnership, + selector!("renounce_ownership"), + selector!("renounceOwnership"), args.span() ) .unwrap_syscall(); diff --git a/src/account/dual_account.cairo b/src/account/dual_account.cairo index 9e4d321c8..674ea33b9 100644 --- a/src/account/dual_account.cairo +++ b/src/account/dual_account.cairo @@ -4,7 +4,6 @@ use array::ArrayTrait; use array::SpanTrait; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -29,7 +28,7 @@ impl DualCaseAccountImpl of DualCaseAccountABI { let mut args = array![new_public_key]; try_selector_with_fallback( - *self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span() + *self.contract_address, selector!("set_public_key"), selector!("setPublicKey"), args.span() ) .unwrap_syscall(); } @@ -38,7 +37,7 @@ impl DualCaseAccountImpl of DualCaseAccountABI { let mut args = array![]; try_selector_with_fallback( - *self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span() + *self.contract_address, selector!("get_public_key"), selector!("getPublicKey"), args.span() ) .unwrap_and_cast() } @@ -51,8 +50,8 @@ impl DualCaseAccountImpl of DualCaseAccountABI { try_selector_with_fallback( *self.contract_address, - selectors::is_valid_signature, - selectors::isValidSignature, + selector!("is_valid_signature"), + selector!("isValidSignature"), args.span() ) .unwrap_and_cast() @@ -63,8 +62,8 @@ impl DualCaseAccountImpl of DualCaseAccountABI { try_selector_with_fallback( *self.contract_address, - selectors::supports_interface, - selectors::supportsInterface, + selector!("supports_interface"), + selector!("supportsInterface"), args.span() ) .unwrap_and_cast() diff --git a/src/introspection/dual_src5.cairo b/src/introspection/dual_src5.cairo index 48d7c9c68..1cfe2947d 100644 --- a/src/introspection/dual_src5.cairo +++ b/src/introspection/dual_src5.cairo @@ -3,7 +3,6 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -22,8 +21,8 @@ impl DualCaseSRC5Impl of DualCaseSRC5Trait { try_selector_with_fallback( *self.contract_address, - selectors::supports_interface, - selectors::supportsInterface, + selector!("supports_interface"), + selector!("supportsInterface"), args.span() ) .unwrap_and_cast() diff --git a/src/token/erc20/dual20.cairo b/src/token/erc20/dual20.cairo index 28897c6f5..2e79ca8f8 100644 --- a/src/token/erc20/dual20.cairo +++ b/src/token/erc20/dual20.cairo @@ -3,7 +3,6 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -32,26 +31,26 @@ trait DualERC20Trait { impl DualERC20Impl of DualERC20Trait { fn name(self: @DualERC20) -> felt252 { let args = array![]; - call_contract_syscall(*self.contract_address, selectors::name, args.span()) + call_contract_syscall(*self.contract_address, selector!("name"), args.span()) .unwrap_and_cast() } fn symbol(self: @DualERC20) -> felt252 { let args = array![]; - call_contract_syscall(*self.contract_address, selectors::symbol, args.span()) + call_contract_syscall(*self.contract_address, selector!("symbol"), args.span()) .unwrap_and_cast() } fn decimals(self: @DualERC20) -> u8 { let args = array![]; - call_contract_syscall(*self.contract_address, selectors::decimals, args.span()) + call_contract_syscall(*self.contract_address, selector!("decimals"), args.span()) .unwrap_and_cast() } fn total_supply(self: @DualERC20) -> u256 { let mut args = array![]; try_selector_with_fallback( - *self.contract_address, selectors::total_supply, selectors::totalSupply, args.span() + *self.contract_address, selector!("total_supply"), selector!("totalSupply"), args.span() ) .unwrap_and_cast() } @@ -61,7 +60,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() + *self.contract_address, selector!("balance_of"), selector!("balanceOf"), args.span() ) .unwrap_and_cast() } @@ -71,7 +70,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(owner); args.append_serde(spender); - call_contract_syscall(*self.contract_address, selectors::allowance, args.span()) + call_contract_syscall(*self.contract_address, selector!("allowance"), args.span()) .unwrap_and_cast() } @@ -80,7 +79,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(recipient); args.append_serde(amount); - call_contract_syscall(*self.contract_address, selectors::transfer, args.span()) + call_contract_syscall(*self.contract_address, selector!("transfer"), args.span()) .unwrap_and_cast() } @@ -93,7 +92,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(amount); try_selector_with_fallback( - *self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span() + *self.contract_address, selector!("transfer_from"), selector!("transferFrom"), args.span() ) .unwrap_and_cast() } @@ -103,7 +102,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(spender); args.append_serde(amount); - call_contract_syscall(*self.contract_address, selectors::approve, args.span()) + call_contract_syscall(*self.contract_address, selector!("approve"), args.span()) .unwrap_and_cast() } } diff --git a/src/token/erc721/dual721.cairo b/src/token/erc721/dual721.cairo index 88cc35abd..cb2b3336e 100644 --- a/src/token/erc721/dual721.cairo +++ b/src/token/erc721/dual721.cairo @@ -3,7 +3,6 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -42,12 +41,12 @@ trait DualCaseERC721Trait { impl DualCaseERC721Impl of DualCaseERC721Trait { fn name(self: @DualCaseERC721) -> felt252 { - call_contract_syscall(*self.contract_address, selectors::name, array![].span()) + call_contract_syscall(*self.contract_address, selector!("name"), array![].span()) .unwrap_and_cast() } fn symbol(self: @DualCaseERC721) -> felt252 { - call_contract_syscall(*self.contract_address, selectors::symbol, array![].span()) + call_contract_syscall(*self.contract_address, selector!("symbol"), array![].span()) .unwrap_and_cast() } @@ -56,7 +55,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selectors::token_uri, selectors::tokenUri, args.span() + *self.contract_address, selector!("token_uri"), selector!("tokenUri"), args.span() ) .unwrap_and_cast() } @@ -66,7 +65,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() + *self.contract_address, selector!("balance_of"), selector!("balanceOf"), args.span() ) .unwrap_and_cast() } @@ -76,7 +75,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selectors::owner_of, selectors::ownerOf, args.span() + *self.contract_address, selector!("owner_of"), selector!("ownerOf"), args.span() ) .unwrap_and_cast() } @@ -86,7 +85,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selectors::get_approved, selectors::getApproved, args.span() + *self.contract_address, selector!("get_approved"), selector!("getApproved"), args.span() ) .unwrap_and_cast() } @@ -100,8 +99,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selectors::is_approved_for_all, - selectors::isApprovedForAll, + selector!("is_approved_for_all"), + selector!("isApprovedForAll"), args.span() ) .unwrap_and_cast() @@ -111,7 +110,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { let mut args = array![]; args.append_serde(to); args.append_serde(token_id); - call_contract_syscall(*self.contract_address, selectors::approve, args.span()) + call_contract_syscall(*self.contract_address, selector!("approve"), args.span()) .unwrap_syscall(); } @@ -122,8 +121,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selectors::set_approval_for_all, - selectors::setApprovalForAll, + selector!("set_approval_for_all"), + selector!("setApprovalForAll"), args.span() ) .unwrap_syscall(); @@ -138,7 +137,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span() + *self.contract_address, selector!("transfer_from"), selector!("transferFrom"), args.span() ) .unwrap_syscall(); } @@ -158,8 +157,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selectors::safe_transfer_from, - selectors::safeTransferFrom, + selector!("safe_transfer_from"), + selector!("safeTransferFrom"), args.span() ) .unwrap_syscall(); @@ -171,8 +170,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selectors::supports_interface, - selectors::supportsInterface, + selector!("supports_interface"), + selector!("supportsInterface"), args.span() ) .unwrap_and_cast() diff --git a/src/token/erc721/dual721_receiver.cairo b/src/token/erc721/dual721_receiver.cairo index 650285d6d..add9bd5ef 100644 --- a/src/token/erc721/dual721_receiver.cairo +++ b/src/token/erc721/dual721_receiver.cairo @@ -3,7 +3,6 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -40,8 +39,8 @@ impl DualCaseERC721ReceiverImpl of DualCaseERC721ReceiverTrait { try_selector_with_fallback( *self.contract_address, - selectors::on_erc721_received, - selectors::onERC721Received, + selector!("on_erc721_received"), + selector!("onERC721Received"), args.span() ) .unwrap_and_cast() From a03a0de4d60204b96a29544dacb4a92838c83392 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 29 Aug 2023 11:53:55 -0400 Subject: [PATCH 02/10] use inline selector --- src/tests/account/test_account.cairo | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 83bea533b..c4c2941bf 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -16,7 +16,6 @@ use openzeppelin::tests::utils::constants::ZERO; use openzeppelin::token::erc20::ERC20; use openzeppelin::token::erc20::interface::IERC20Dispatcher; use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use option::OptionTrait; use serde::Serde; @@ -300,7 +299,7 @@ fn test_execute_with_version(version: Option) { calldata.append_serde(recipient); calldata.append_serde(amount); let call = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata }; let mut calls = array![]; calls.append(call); @@ -378,7 +377,7 @@ fn test_multicall() { calldata1.append_serde(recipient1); calldata1.append_serde(amount1); let call1 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1 + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1 }; // Craft call2 @@ -387,7 +386,7 @@ fn test_multicall() { calldata2.append_serde(recipient2); calldata2.append_serde(amount2); let call2 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2 + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2 }; // Bundle calls and exeute From 953011c52ed330c45ca16fc7d361407d842b4edd Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 29 Aug 2023 11:54:13 -0400 Subject: [PATCH 03/10] remove selectors file --- src/utils/selectors.cairo | 93 --------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 src/utils/selectors.cairo diff --git a/src/utils/selectors.cairo b/src/utils/selectors.cairo deleted file mode 100644 index 1695e17cb..000000000 --- a/src/utils/selectors.cairo +++ /dev/null @@ -1,93 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.7.0 (utils/selectors.cairo) - -// -// AccessControl -// - -const get_role_admin: felt252 = 0x302e0454f48778e0ca3a2e714a289c4e8d8e03d614b370130abb1a524a47f22; -const getRoleAdmin: felt252 = 0x2034da88f3e3f3382ab0faf97fe5f74fe34d551ddff7fda974d756bf12130a0; -const grant_role: felt252 = 0x18a2f881894a5eb15a2a00f598839abaa75bd7f1fea1a37e42779d7fbcd9cf8; -const grantRole: felt252 = 0x37322ff1aabefe50aec25a14eb84b168b7be4f2d66fbbdb5dd8135e8234c37a; -const has_role: felt252 = 0x30559321b47d576b645ed7bd24089943dd5fd3a359ecdd6fa8f05c1bab67d6b; -const hasRole: felt252 = 0x35ed3407ba17dc741dd3af821fa1548619ebcdc87c95bcea9e3bc510951fae8; -const renounce_role: felt252 = 0xd80093a4ee6a9e649f2ae3c64963d5096948d50cf4ea055500aa03a342fd43; -const renounceRole: felt252 = 0x3c4022816cd5119ac7938fd7a982062e4cacd4777b4eda6e6a8f64d9e6833; -const revoke_role: felt252 = 0x246116ed358bad337e64a4df51cb57a40929189494ad5905a39872c489136ec; -const revokeRole: felt252 = 0xa7ef1739dec1e216a0ba2987650983a3104c707ad0831a30184a3b1382dd7d; - -// -// Ownable -// - -const owner: felt252 = 0x2016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0; -const transfer_ownership: felt252 = - 0x2a3bb1eaa05b77c4b0eeee0116a3177c6d62319dd7149ae148185d9e09de74a; -const transferOwnership: felt252 = - 0x14a390f291e2e1f29874769efdef47ddad94d76f77ff516fad206a385e8995f; -const renounce_ownership: felt252 = 0x52580a92c73f4428f1a260c5d768ef462b25955307de00f99957df119865d; -const renounceOwnership: felt252 = 0xd5d33d590e6660853069b37a2aea67c6fdaa0268626bc760350b590490feb5; - -// -// ERC721 -// - -const name: felt252 = 0x361458367e696363fbcc70777d07ebbd2394e89fd0adcaf147faccd1d294d60; -const symbol: felt252 = 0x216b05c387bab9ac31918a3e61672f4618601f3c598a2f3f2710f37053e1ea4; -const token_uri: felt252 = 0x226ad7e84c1fe08eb4c525ed93cccadf9517670341304571e66f7c4f95cbe54; -const tokenUri: felt252 = 0x362dec5b8b67ab667ad08e83a2c3ba1db7fdb4ab8dc3a33c057c4fddec8d3de; -const balance_of: felt252 = 0x35a73cd311a05d46deda634c5ee045db92f811b4e74bca4437fcb5302b7af33; -const balanceOf: felt252 = 0x2e4263afad30923c891518314c3c95dbe830a16874e8abc5777a9a20b54c76e; -const owner_of: felt252 = 0x3552df12bdc6089cf963c40c4cf56fbfd4bd14680c244d1c5494c2790f1ea5c; -const ownerOf: felt252 = 0x2962ba17806af798afa6eaf4aa8c93a9fb60a3e305045b6eea33435086cae9; -const get_approved: felt252 = 0x309065f1424d76d4a4ace2ff671391d59536e0297409434908d38673290a749; -const getApproved: felt252 = 0xb180e2fe9f14914416216da76338ac0beb980443725c802af615f8431fdb1e; -const is_approved_for_all: felt252 = - 0x2aa3ea196f9b8a4f65613b67fcf185e69d8faa9601a3382871d15b3060e30dd; -const isApprovedForAll: felt252 = 0x21cdf9aedfed41bc4485ae779fda471feca12075d9127a0fc70ac6b3b3d9c30; -const approve: felt252 = 0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c; -const set_approval_for_all: felt252 = - 0xd86ca3d41635e20c180181046b11abcf19e1bdef3dcaa4c180300ccca1813f; -const setApprovalForAll: felt252 = - 0x2d4c8ea4c8fb9f571d1f6f9b7692fff8e5ceaf73b1df98e7da8c1109b39ae9a; -const transfer_from: felt252 = 0x3704ffe8fba161be0e994951751a5033b1462b918ff785c0a636be718dfdb68; -const transferFrom: felt252 = 0x41b033f4a31df8067c24d1e9b550a2ce75fd4a29e1147af9752174f0e6cb20; -const safe_transfer_from: felt252 = - 0x16f0218b33b5cf273196787d7cf139a9ad13d58e6674dcdce722b3bf8389863; -const safeTransferFrom: felt252 = 0x19d59d013d4aa1a8b1ce4c8299086f070733b453c02d0dc46e735edc04d6444; - -// -// ERC721Receiver -// - -const on_erc721_received: felt252 = - 0x38c7ee9f0855dfe219aea022b141d9b2ec0f6b68395d221c3f331c7ca4fb608; -const onERC721Received: felt252 = 0xfa119a8fafc6f1a02deb36fe5efbcc4929ef2021e50cf1cb6d1a780ccd009b; - -// -// ERC20 -// - -// The following ERC20 selectors are already defined in ERC721 above: -// name, symbol, balance_of, balanceOf, transfer_from, transferFrom, approve -const decimals: felt252 = 0x4c4fb1ab068f6039d5780c68dd0fa2f8742cceb3426d19667778ca7f3518a9; -const total_supply: felt252 = 0x1557182e4359a1f0c6301278e8f5b35a776ab58d39892581e357578fb287836; -const totalSupply: felt252 = 0x80aa9fdbfaf9615e4afc7f5f722e265daca5ccc655360fa5ccacf9c267936d; -const allowance: felt252 = 0x1e888a1026b19c8c0b57c72d63ed1737106aa10034105b980ba117bd0c29fe1; -const transfer: felt252 = 0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e; - -// -// Account -// - -const set_public_key: felt252 = 0x2e3e21ff5952b2531241e37999d9c4c8b3034cccc89a202a6bf019bdf5294f9; -const setPublicKey: felt252 = 0xbc0eb87884ab91e330445c3584a50d7ddf4b568f02fbeb456a6242cce3f5d9; -const get_public_key: felt252 = 0x1a35984e05126dbecb7c3bb9929e7dd9106d460c59b1633739a5c733a5fb13b; -const getPublicKey: felt252 = 0x1a6c6a0bdec86cc645c91997d8eea83e87148659e3e61122f72361fd5e94079; -const is_valid_signature: felt252 = - 0x28420862938116cb3bbdbedee07451ccc54d4e9412dbef71142ad1980a30941; -const isValidSignature: felt252 = 0x213dfe25e2ca309c4d615a09cfc95fdb2fc7dc73fbcad12c450fe93b1f2ff9e; -const supports_interface: felt252 = - 0xfe80f537b66d12a00b6d3c072b44afbb716e78dde5c3f0ef116ee93d3e3283; -const supportsInterface: felt252 = - 0x29e211664c0b63c79638fbea474206ca74016b3e9a3dc4f9ac300ffd8bdf2cd; From 45c689b835a1eadad69ae542d86666a779af7399 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 29 Aug 2023 11:55:41 -0400 Subject: [PATCH 04/10] remove import --- src/utils.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils.cairo b/src/utils.cairo index 38b0b35dd..932ec0a88 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -2,7 +2,6 @@ // OpenZeppelin Contracts for Cairo v0.7.0 (utils.cairo) mod constants; -mod selectors; mod serde; mod unwrap_and_cast; From a64416df6e855d43fc25e0cb58887445eb710f3b Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Sep 2023 12:07:53 -0400 Subject: [PATCH 05/10] fix camel tokenURI --- src/tests/mocks/camel721_mock.cairo | 4 ++-- src/tests/mocks/erc721_panic_mock.cairo | 2 +- src/tests/token/test_dual721.cairo | 4 ++-- src/token/erc721/dual721.cairo | 2 +- src/token/erc721/erc721.cairo | 2 +- src/token/erc721/interface.cairo | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tests/mocks/camel721_mock.cairo b/src/tests/mocks/camel721_mock.cairo index 9fcbbb248..2117697d8 100644 --- a/src/tests/mocks/camel721_mock.cairo +++ b/src/tests/mocks/camel721_mock.cairo @@ -38,9 +38,9 @@ mod CamelERC721Mock { } #[external(v0)] - fn tokenUri(self: @ContractState, tokenId: u256) -> felt252 { + fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { let unsafe_state = ERC721::unsafe_new_contract_state(); - ERC721::ERC721MetadataCamelOnlyImpl::tokenUri(@unsafe_state, tokenId) + ERC721::ERC721MetadataCamelOnlyImpl::tokenURI(@unsafe_state, tokenId) } #[external(v0)] diff --git a/src/tests/mocks/erc721_panic_mock.cairo b/src/tests/mocks/erc721_panic_mock.cairo index 6d172c379..ace550d33 100644 --- a/src/tests/mocks/erc721_panic_mock.cairo +++ b/src/tests/mocks/erc721_panic_mock.cairo @@ -107,7 +107,7 @@ mod CamelERC721PanicMock { } #[external(v0)] - fn tokenUri(self: @ContractState, tokenId: u256) -> felt252 { + fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { panic_with_felt252('Some error'); 3 } diff --git a/src/tests/token/test_dual721.cairo b/src/tests/token/test_dual721.cairo index 6c1744258..fc65cc426 100644 --- a/src/tests/token/test_dual721.cairo +++ b/src/tests/token/test_dual721.cairo @@ -525,7 +525,7 @@ fn test_dual_isApprovedForAll_exists_and_panics() { #[test] #[available_gas(2000000)] -fn test_dual_tokenUri() { +fn test_dual_tokenURI() { let (dispatcher, target) = setup_camel(); assert(dispatcher.token_uri(TOKEN_ID) == URI, 'Should return URI'); } @@ -533,7 +533,7 @@ fn test_dual_tokenUri() { #[test] #[available_gas(2000000)] #[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] -fn test_dual_tokenUri_exists_and_panics() { +fn test_dual_tokenURI_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.token_uri(TOKEN_ID); } diff --git a/src/token/erc721/dual721.cairo b/src/token/erc721/dual721.cairo index cb2b3336e..43a7b6572 100644 --- a/src/token/erc721/dual721.cairo +++ b/src/token/erc721/dual721.cairo @@ -55,7 +55,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selector!("token_uri"), selector!("tokenUri"), args.span() + *self.contract_address, selector!("token_uri"), selector!("tokenURI"), args.span() ) .unwrap_and_cast() } diff --git a/src/token/erc721/erc721.cairo b/src/token/erc721/erc721.cairo index 70ae7cd39..0abffb4d1 100644 --- a/src/token/erc721/erc721.cairo +++ b/src/token/erc721/erc721.cairo @@ -110,7 +110,7 @@ mod ERC721 { #[external(v0)] impl ERC721MetadataCamelOnlyImpl of interface::IERC721MetadataCamelOnly { - fn tokenUri(self: @ContractState, tokenId: u256) -> felt252 { + fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { assert(self._exists(tokenId), 'ERC721: invalid token ID'); self._token_uri.read(tokenId) } diff --git a/src/token/erc721/interface.cairo b/src/token/erc721/interface.cairo index 4aff670b8..86125721d 100644 --- a/src/token/erc721/interface.cairo +++ b/src/token/erc721/interface.cairo @@ -60,7 +60,7 @@ trait IERC721Metadata { #[starknet::interface] trait IERC721MetadataCamelOnly { - fn tokenUri(self: @TState, tokenId: u256) -> felt252; + fn tokenURI(self: @TState, tokenId: u256) -> felt252; } // From 79c8f8592945e74246fe5f7b9eca5649cfe9c94b Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Sep 2023 12:09:15 -0400 Subject: [PATCH 06/10] fix formatting --- src/access/accesscontrol/dual_accesscontrol.cairo | 10 ++++++++-- src/account/dual_account.cairo | 10 ++++++++-- src/token/erc20/dual20.cairo | 5 ++++- src/token/erc721/dual721.cairo | 5 ++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/access/accesscontrol/dual_accesscontrol.cairo b/src/access/accesscontrol/dual_accesscontrol.cairo index 8bd7cbc91..3897242a3 100644 --- a/src/access/accesscontrol/dual_accesscontrol.cairo +++ b/src/access/accesscontrol/dual_accesscontrol.cairo @@ -41,7 +41,10 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(role); try_selector_with_fallback( - *self.contract_address, selector!("get_role_admin"), selector!("getRoleAdmin"), args.span() + *self.contract_address, + selector!("get_role_admin"), + selector!("getRoleAdmin"), + args.span() ) .unwrap_and_cast() } @@ -74,7 +77,10 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selector!("renounce_role"), selector!("renounceRole"), args.span() + *self.contract_address, + selector!("renounce_role"), + selector!("renounceRole"), + args.span() ) .unwrap_syscall(); } diff --git a/src/account/dual_account.cairo b/src/account/dual_account.cairo index 674ea33b9..8aa5a6010 100644 --- a/src/account/dual_account.cairo +++ b/src/account/dual_account.cairo @@ -28,7 +28,10 @@ impl DualCaseAccountImpl of DualCaseAccountABI { let mut args = array![new_public_key]; try_selector_with_fallback( - *self.contract_address, selector!("set_public_key"), selector!("setPublicKey"), args.span() + *self.contract_address, + selector!("set_public_key"), + selector!("setPublicKey"), + args.span() ) .unwrap_syscall(); } @@ -37,7 +40,10 @@ impl DualCaseAccountImpl of DualCaseAccountABI { let mut args = array![]; try_selector_with_fallback( - *self.contract_address, selector!("get_public_key"), selector!("getPublicKey"), args.span() + *self.contract_address, + selector!("get_public_key"), + selector!("getPublicKey"), + args.span() ) .unwrap_and_cast() } diff --git a/src/token/erc20/dual20.cairo b/src/token/erc20/dual20.cairo index 2e79ca8f8..c60004c32 100644 --- a/src/token/erc20/dual20.cairo +++ b/src/token/erc20/dual20.cairo @@ -92,7 +92,10 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(amount); try_selector_with_fallback( - *self.contract_address, selector!("transfer_from"), selector!("transferFrom"), args.span() + *self.contract_address, + selector!("transfer_from"), + selector!("transferFrom"), + args.span() ) .unwrap_and_cast() } diff --git a/src/token/erc721/dual721.cairo b/src/token/erc721/dual721.cairo index 43a7b6572..940c1774f 100644 --- a/src/token/erc721/dual721.cairo +++ b/src/token/erc721/dual721.cairo @@ -137,7 +137,10 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selector!("transfer_from"), selector!("transferFrom"), args.span() + *self.contract_address, + selector!("transfer_from"), + selector!("transferFrom"), + args.span() ) .unwrap_syscall(); } From 28c7bd6d4b007276dfa3d59d86215f87b16103f7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 8 Sep 2023 13:02:37 -0400 Subject: [PATCH 07/10] re-add selectors mod --- src/utils.cairo | 1 + src/utils/selectors.cairo | 93 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/utils/selectors.cairo diff --git a/src/utils.cairo b/src/utils.cairo index 932ec0a88..38b0b35dd 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -2,6 +2,7 @@ // OpenZeppelin Contracts for Cairo v0.7.0 (utils.cairo) mod constants; +mod selectors; mod serde; mod unwrap_and_cast; diff --git a/src/utils/selectors.cairo b/src/utils/selectors.cairo new file mode 100644 index 000000000..66d49fb99 --- /dev/null +++ b/src/utils/selectors.cairo @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: MIT +// OpenZeppelin Contracts for Cairo v0.7.0 (utils/selectors.cairo) + +// +// AccessControl +// + +const get_role_admin: felt252 = selector!("get_role_admin"); +const getRoleAdmin: felt252 = selector!("getRoleAdmin"); +const grant_role: felt252 = selector!("grant_role"); +const grantRole: felt252 = selector!("grantRole"); +const has_role: felt252 = selector!("has_role"); +const hasRole: felt252 = selector!("hasRole"); +const renounce_role: felt252 = selector!("renounce_role"); +const renounceRole: felt252 = selector!("renounceRole"); +const revoke_role: felt252 = selector!("revoke_role"); +const revokeRole: felt252 = selector!("revokeRole"); + +// +// Ownable +// + +const owner: felt252 = selector!("owner"); +const transfer_ownership: felt252 = + selector!("transfer_ownership"); +const transferOwnership: felt252 = + selector!("transferOwnership"); +const renounce_ownership: felt252 = selector!("renounce_ownership"); +const renounceOwnership: felt252 = selector!("renounceOwnership"); + +// +// ERC721 +// + +const name: felt252 = selector!("name"); +const symbol: felt252 = selector!("symbol"); +const token_uri: felt252 = selector!("token_uri"); +const tokenURI: felt252 = selector!("tokenURI"); +const balance_of: felt252 = selector!("balance_of"); +const balanceOf: felt252 = selector!("balanceOf"); +const owner_of: felt252 = selector!("owner_of"); +const ownerOf: felt252 = selector!("ownerOf"); +const get_approved: felt252 = selector!("get_approved"); +const getApproved: felt252 = selector!("getApproved"); +const is_approved_for_all: felt252 = + selector!("is_approved_for_all"); +const isApprovedForAll: felt252 = selector!("isApprovedForAll"); +const approve: felt252 = selector!("approve"); +const set_approval_for_all: felt252 = + selector!("set_approval_for_all"); +const setApprovalForAll: felt252 = + selector!("setApprovalForAll"); +const transfer_from: felt252 = selector!("transfer_from"); +const transferFrom: felt252 = selector!("transferFrom"); +const safe_transfer_from: felt252 = + selector!("safe_transfer_from"); +const safeTransferFrom: felt252 = selector!("safeTransferFrom"); + +// +// ERC721Receiver +// + +const on_erc721_received: felt252 = + selector!("on_erc721_received"); +const onERC721Received: felt252 = selector!("onERC721Received"); + +// +// ERC20 +// + +// The following ERC20 selectors are already defined in ERC721 above: +// name, symbol, balance_of, balanceOf, transfer_from, transferFrom, approve +const decimals: felt252 = selector!("decimals"); +const total_supply: felt252 = selector!("total_supply"); +const totalSupply: felt252 = selector!("totalSupply"); +const allowance: felt252 = selector!("allowance"); +const transfer: felt252 = selector!("transfer"); + +// +// Account +// + +const set_public_key: felt252 = selector!("set_public_key"); +const setPublicKey: felt252 = selector!("setPublicKey"); +const get_public_key: felt252 = selector!("get_public_key"); +const getPublicKey: felt252 = selector!("getPublicKey"); +const is_valid_signature: felt252 = + selector!("is_valid_signature"); +const isValidSignature: felt252 = selector!("isValidSignature"); +const supports_interface: felt252 = + selector!("supports_interface"); +const supportsInterface: felt252 = + selector!("supportsInterface"); From b84f9f0c7b94391aec79777b6846457c116f8d5e Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 8 Sep 2023 13:03:08 -0400 Subject: [PATCH 08/10] import from selectors mod --- .../accesscontrol/dual_accesscontrol.cairo | 21 +++++------ src/access/ownable/dual_ownable.cairo | 11 +++--- src/account/dual_account.cairo | 19 ++++------ src/introspection/dual_src5.cairo | 5 +-- src/token/erc20/dual20.cairo | 22 ++++++------ src/token/erc721/dual721.cairo | 36 +++++++++---------- src/token/erc721/dual721_receiver.cairo | 5 +-- 7 files changed, 54 insertions(+), 65 deletions(-) diff --git a/src/access/accesscontrol/dual_accesscontrol.cairo b/src/access/accesscontrol/dual_accesscontrol.cairo index 3897242a3..eb086840e 100644 --- a/src/access/accesscontrol/dual_accesscontrol.cairo +++ b/src/access/accesscontrol/dual_accesscontrol.cairo @@ -5,6 +5,7 @@ use array::ArrayTrait; use openzeppelin::utils::Felt252TryIntoBool; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -31,7 +32,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selector!("has_role"), selector!("hasRole"), args.span() + *self.contract_address, selectors::has_role, selectors::hasRole, args.span() ) .unwrap_and_cast() } @@ -41,10 +42,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(role); try_selector_with_fallback( - *self.contract_address, - selector!("get_role_admin"), - selector!("getRoleAdmin"), - args.span() + *self.contract_address, selectors::get_role_admin, selectors::getRoleAdmin, args.span() ) .unwrap_and_cast() } @@ -55,7 +53,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selector!("grant_role"), selector!("grantRole"), args.span() + *self.contract_address, selectors::grant_role, selectors::grantRole, args.span() ) .unwrap_syscall(); } @@ -66,7 +64,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selector!("revoke_role"), selector!("revokeRole"), args.span() + *self.contract_address, selectors::revoke_role, selectors::revokeRole, args.span() ) .unwrap_syscall(); } @@ -77,10 +75,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, - selector!("renounce_role"), - selector!("renounceRole"), - args.span() + *self.contract_address, selectors::renounce_role, selectors::renounceRole, args.span() ) .unwrap_syscall(); } @@ -91,8 +86,8 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { try_selector_with_fallback( *self.contract_address, - selector!("supports_interface"), - selector!("supportsInterface"), + selectors::supports_interface, + selectors::supportsInterface, args.span() ) .unwrap_and_cast() diff --git a/src/access/ownable/dual_ownable.cairo b/src/access/ownable/dual_ownable.cairo index 670bb0924..03d2ba51b 100644 --- a/src/access/ownable/dual_ownable.cairo +++ b/src/access/ownable/dual_ownable.cairo @@ -7,6 +7,7 @@ use core::result::ResultTrait; use openzeppelin::utils::Felt252TryIntoBool; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use option::OptionTrait; @@ -31,7 +32,7 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { fn owner(self: @DualCaseOwnable) -> ContractAddress { let args = ArrayTrait::new(); - call_contract_syscall(*self.contract_address, selector!("owner"), args.span()) + call_contract_syscall(*self.contract_address, selectors::owner, args.span()) .unwrap_and_cast() } @@ -41,8 +42,8 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { try_selector_with_fallback( *self.contract_address, - selector!("transfer_ownership"), - selector!("transferOwnership"), + selectors::transfer_ownership, + selectors::transferOwnership, args.span() ) .unwrap_syscall(); @@ -53,8 +54,8 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { try_selector_with_fallback( *self.contract_address, - selector!("renounce_ownership"), - selector!("renounceOwnership"), + selectors::renounce_ownership, + selectors::renounceOwnership, args.span() ) .unwrap_syscall(); diff --git a/src/account/dual_account.cairo b/src/account/dual_account.cairo index 8aa5a6010..9e4d321c8 100644 --- a/src/account/dual_account.cairo +++ b/src/account/dual_account.cairo @@ -4,6 +4,7 @@ use array::ArrayTrait; use array::SpanTrait; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -28,10 +29,7 @@ impl DualCaseAccountImpl of DualCaseAccountABI { let mut args = array![new_public_key]; try_selector_with_fallback( - *self.contract_address, - selector!("set_public_key"), - selector!("setPublicKey"), - args.span() + *self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span() ) .unwrap_syscall(); } @@ -40,10 +38,7 @@ impl DualCaseAccountImpl of DualCaseAccountABI { let mut args = array![]; try_selector_with_fallback( - *self.contract_address, - selector!("get_public_key"), - selector!("getPublicKey"), - args.span() + *self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span() ) .unwrap_and_cast() } @@ -56,8 +51,8 @@ impl DualCaseAccountImpl of DualCaseAccountABI { try_selector_with_fallback( *self.contract_address, - selector!("is_valid_signature"), - selector!("isValidSignature"), + selectors::is_valid_signature, + selectors::isValidSignature, args.span() ) .unwrap_and_cast() @@ -68,8 +63,8 @@ impl DualCaseAccountImpl of DualCaseAccountABI { try_selector_with_fallback( *self.contract_address, - selector!("supports_interface"), - selector!("supportsInterface"), + selectors::supports_interface, + selectors::supportsInterface, args.span() ) .unwrap_and_cast() diff --git a/src/introspection/dual_src5.cairo b/src/introspection/dual_src5.cairo index 1cfe2947d..48d7c9c68 100644 --- a/src/introspection/dual_src5.cairo +++ b/src/introspection/dual_src5.cairo @@ -3,6 +3,7 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -21,8 +22,8 @@ impl DualCaseSRC5Impl of DualCaseSRC5Trait { try_selector_with_fallback( *self.contract_address, - selector!("supports_interface"), - selector!("supportsInterface"), + selectors::supports_interface, + selectors::supportsInterface, args.span() ) .unwrap_and_cast() diff --git a/src/token/erc20/dual20.cairo b/src/token/erc20/dual20.cairo index c60004c32..28897c6f5 100644 --- a/src/token/erc20/dual20.cairo +++ b/src/token/erc20/dual20.cairo @@ -3,6 +3,7 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -31,26 +32,26 @@ trait DualERC20Trait { impl DualERC20Impl of DualERC20Trait { fn name(self: @DualERC20) -> felt252 { let args = array![]; - call_contract_syscall(*self.contract_address, selector!("name"), args.span()) + call_contract_syscall(*self.contract_address, selectors::name, args.span()) .unwrap_and_cast() } fn symbol(self: @DualERC20) -> felt252 { let args = array![]; - call_contract_syscall(*self.contract_address, selector!("symbol"), args.span()) + call_contract_syscall(*self.contract_address, selectors::symbol, args.span()) .unwrap_and_cast() } fn decimals(self: @DualERC20) -> u8 { let args = array![]; - call_contract_syscall(*self.contract_address, selector!("decimals"), args.span()) + call_contract_syscall(*self.contract_address, selectors::decimals, args.span()) .unwrap_and_cast() } fn total_supply(self: @DualERC20) -> u256 { let mut args = array![]; try_selector_with_fallback( - *self.contract_address, selector!("total_supply"), selector!("totalSupply"), args.span() + *self.contract_address, selectors::total_supply, selectors::totalSupply, args.span() ) .unwrap_and_cast() } @@ -60,7 +61,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selector!("balance_of"), selector!("balanceOf"), args.span() + *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() ) .unwrap_and_cast() } @@ -70,7 +71,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(owner); args.append_serde(spender); - call_contract_syscall(*self.contract_address, selector!("allowance"), args.span()) + call_contract_syscall(*self.contract_address, selectors::allowance, args.span()) .unwrap_and_cast() } @@ -79,7 +80,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(recipient); args.append_serde(amount); - call_contract_syscall(*self.contract_address, selector!("transfer"), args.span()) + call_contract_syscall(*self.contract_address, selectors::transfer, args.span()) .unwrap_and_cast() } @@ -92,10 +93,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(amount); try_selector_with_fallback( - *self.contract_address, - selector!("transfer_from"), - selector!("transferFrom"), - args.span() + *self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span() ) .unwrap_and_cast() } @@ -105,7 +103,7 @@ impl DualERC20Impl of DualERC20Trait { args.append_serde(spender); args.append_serde(amount); - call_contract_syscall(*self.contract_address, selector!("approve"), args.span()) + call_contract_syscall(*self.contract_address, selectors::approve, args.span()) .unwrap_and_cast() } } diff --git a/src/token/erc721/dual721.cairo b/src/token/erc721/dual721.cairo index 940c1774f..041f267a2 100644 --- a/src/token/erc721/dual721.cairo +++ b/src/token/erc721/dual721.cairo @@ -3,6 +3,7 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -41,12 +42,12 @@ trait DualCaseERC721Trait { impl DualCaseERC721Impl of DualCaseERC721Trait { fn name(self: @DualCaseERC721) -> felt252 { - call_contract_syscall(*self.contract_address, selector!("name"), array![].span()) + call_contract_syscall(*self.contract_address, selectors::name, array![].span()) .unwrap_and_cast() } fn symbol(self: @DualCaseERC721) -> felt252 { - call_contract_syscall(*self.contract_address, selector!("symbol"), array![].span()) + call_contract_syscall(*self.contract_address, selectors::symbol, array![].span()) .unwrap_and_cast() } @@ -55,7 +56,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selector!("token_uri"), selector!("tokenURI"), args.span() + *self.contract_address, selectors::token_uri, selectors::tokenURI, args.span() ) .unwrap_and_cast() } @@ -65,7 +66,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(account); try_selector_with_fallback( - *self.contract_address, selector!("balance_of"), selector!("balanceOf"), args.span() + *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() ) .unwrap_and_cast() } @@ -75,7 +76,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selector!("owner_of"), selector!("ownerOf"), args.span() + *self.contract_address, selectors::owner_of, selectors::ownerOf, args.span() ) .unwrap_and_cast() } @@ -85,7 +86,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, selector!("get_approved"), selector!("getApproved"), args.span() + *self.contract_address, selectors::get_approved, selectors::getApproved, args.span() ) .unwrap_and_cast() } @@ -99,8 +100,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selector!("is_approved_for_all"), - selector!("isApprovedForAll"), + selectors::is_approved_for_all, + selectors::isApprovedForAll, args.span() ) .unwrap_and_cast() @@ -110,7 +111,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { let mut args = array![]; args.append_serde(to); args.append_serde(token_id); - call_contract_syscall(*self.contract_address, selector!("approve"), args.span()) + call_contract_syscall(*self.contract_address, selectors::approve, args.span()) .unwrap_syscall(); } @@ -121,8 +122,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selector!("set_approval_for_all"), - selector!("setApprovalForAll"), + selectors::set_approval_for_all, + selectors::setApprovalForAll, args.span() ) .unwrap_syscall(); @@ -137,10 +138,7 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { args.append_serde(token_id); try_selector_with_fallback( - *self.contract_address, - selector!("transfer_from"), - selector!("transferFrom"), - args.span() + *self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span() ) .unwrap_syscall(); } @@ -160,8 +158,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selector!("safe_transfer_from"), - selector!("safeTransferFrom"), + selectors::safe_transfer_from, + selectors::safeTransferFrom, args.span() ) .unwrap_syscall(); @@ -173,8 +171,8 @@ impl DualCaseERC721Impl of DualCaseERC721Trait { try_selector_with_fallback( *self.contract_address, - selector!("supports_interface"), - selector!("supportsInterface"), + selectors::supports_interface, + selectors::supportsInterface, args.span() ) .unwrap_and_cast() diff --git a/src/token/erc721/dual721_receiver.cairo b/src/token/erc721/dual721_receiver.cairo index add9bd5ef..650285d6d 100644 --- a/src/token/erc721/dual721_receiver.cairo +++ b/src/token/erc721/dual721_receiver.cairo @@ -3,6 +3,7 @@ use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; use starknet::ContractAddress; @@ -39,8 +40,8 @@ impl DualCaseERC721ReceiverImpl of DualCaseERC721ReceiverTrait { try_selector_with_fallback( *self.contract_address, - selector!("on_erc721_received"), - selector!("onERC721Received"), + selectors::on_erc721_received, + selectors::onERC721Received, args.span() ) .unwrap_and_cast() From 597c9c0a643ef914d918d48bb114171ff96d0ff5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 8 Sep 2023 13:03:34 -0400 Subject: [PATCH 09/10] fix formatting --- src/utils/selectors.cairo | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/utils/selectors.cairo b/src/utils/selectors.cairo index 66d49fb99..505a35374 100644 --- a/src/utils/selectors.cairo +++ b/src/utils/selectors.cairo @@ -21,10 +21,8 @@ const revokeRole: felt252 = selector!("revokeRole"); // const owner: felt252 = selector!("owner"); -const transfer_ownership: felt252 = - selector!("transfer_ownership"); -const transferOwnership: felt252 = - selector!("transferOwnership"); +const transfer_ownership: felt252 = selector!("transfer_ownership"); +const transferOwnership: felt252 = selector!("transferOwnership"); const renounce_ownership: felt252 = selector!("renounce_ownership"); const renounceOwnership: felt252 = selector!("renounceOwnership"); @@ -42,26 +40,21 @@ const owner_of: felt252 = selector!("owner_of"); const ownerOf: felt252 = selector!("ownerOf"); const get_approved: felt252 = selector!("get_approved"); const getApproved: felt252 = selector!("getApproved"); -const is_approved_for_all: felt252 = - selector!("is_approved_for_all"); +const is_approved_for_all: felt252 = selector!("is_approved_for_all"); const isApprovedForAll: felt252 = selector!("isApprovedForAll"); const approve: felt252 = selector!("approve"); -const set_approval_for_all: felt252 = - selector!("set_approval_for_all"); -const setApprovalForAll: felt252 = - selector!("setApprovalForAll"); +const set_approval_for_all: felt252 = selector!("set_approval_for_all"); +const setApprovalForAll: felt252 = selector!("setApprovalForAll"); const transfer_from: felt252 = selector!("transfer_from"); const transferFrom: felt252 = selector!("transferFrom"); -const safe_transfer_from: felt252 = - selector!("safe_transfer_from"); +const safe_transfer_from: felt252 = selector!("safe_transfer_from"); const safeTransferFrom: felt252 = selector!("safeTransferFrom"); // // ERC721Receiver // -const on_erc721_received: felt252 = - selector!("on_erc721_received"); +const on_erc721_received: felt252 = selector!("on_erc721_received"); const onERC721Received: felt252 = selector!("onERC721Received"); // @@ -84,10 +77,7 @@ const set_public_key: felt252 = selector!("set_public_key"); const setPublicKey: felt252 = selector!("setPublicKey"); const get_public_key: felt252 = selector!("get_public_key"); const getPublicKey: felt252 = selector!("getPublicKey"); -const is_valid_signature: felt252 = - selector!("is_valid_signature"); +const is_valid_signature: felt252 = selector!("is_valid_signature"); const isValidSignature: felt252 = selector!("isValidSignature"); -const supports_interface: felt252 = - selector!("supports_interface"); -const supportsInterface: felt252 = - selector!("supportsInterface"); +const supports_interface: felt252 = selector!("supports_interface"); +const supportsInterface: felt252 = selector!("supportsInterface"); From 7f6f4959ed6e5c570b11caf49ed9276039059785 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 8 Sep 2023 13:23:54 -0400 Subject: [PATCH 10/10] import selector --- src/tests/account/test_account.cairo | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index c4c2941bf..83bea533b 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -16,6 +16,7 @@ use openzeppelin::tests::utils::constants::ZERO; use openzeppelin::token::erc20::ERC20; use openzeppelin::token::erc20::interface::IERC20Dispatcher; use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; +use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use option::OptionTrait; use serde::Serde; @@ -299,7 +300,7 @@ fn test_execute_with_version(version: Option) { calldata.append_serde(recipient); calldata.append_serde(amount); let call = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata + to: erc20.contract_address, selector: selectors::transfer, calldata: calldata }; let mut calls = array![]; calls.append(call); @@ -377,7 +378,7 @@ fn test_multicall() { calldata1.append_serde(recipient1); calldata1.append_serde(amount1); let call1 = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1 + to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1 }; // Craft call2 @@ -386,7 +387,7 @@ fn test_multicall() { calldata2.append_serde(recipient2); calldata2.append_serde(amount2); let call2 = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2 + to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2 }; // Bundle calls and exeute