OpenZeppelin / cairo-contracts

OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup
https://docs.openzeppelin.com/contracts-cairo
MIT License
818 stars 335 forks source link

Add `ERC20_approveFrom` #287

Closed CalabashSquash closed 2 years ago

CalabashSquash commented 2 years ago

🧐 Motivation The solidity implementation of ERC20 has an _approve function, which is an internal function for which the external approve function calls after fetching msg.sender.

Having an internal approval function that not only takes the spender and amount, but also owner allows for further extensions to the ERC20 contracts without having to duplicate much of the approve function body.

For example, ERC20Permit requires this when granting permission based on the EIP712 signatures.

I was trying to implement ERC20Permit in Cairo as a personal learning exercise but realised I would have to re-write much of ERC20_approve to allow for me to approve with a given owner address.

📝 Details

In the solidity implementation, the internal function is prepended with an underscore. This doesn't rely make sense here because of the ERC20_[functionName] format for functions, so I think ERC20_approveFrom is a suitable function name.

I'd like to implement this, but let me know whether this is wanted or not :)

andrew-fleming commented 2 years ago

Hey @CalabashSquash, I totally agree with your points! There's already a PR with a similar change in place #240. It might be a good idea to add the changes from said PR and build off that with permit. I should also note that we're refactoring the libs to utilize namespace (see discussion #267).

andrew-fleming commented 2 years ago

Also, I know you said this is a learning exercise, but EIP712 could be a cool feature to add as an issue/feature request. If it makes sense, it'd be great if you wanted to contribute :)

martriay commented 2 years ago

Superseded by #240