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

RFC: ERC-20 Farm Balance Approval System and Permit Implementation #129

Closed
0xkokonut opened this issue Oct 21, 2022 · 1 comment
Closed
Labels
📜 RFC Formal protocol RFCs

Comments

@0xkokonut
Copy link
Contributor

0xkokonut commented Oct 21, 2022

Abstract

Allows Farmers to delegate their ERC-20 farm balance to other contracts to call transfer on their behalf and add EIP-2612 support to ERC-20 farm balance.

Motivation

Currently, the only way to transfer ERC-20 farm balance is by calling transferToken() on the Farmer's account and there are no ways for farmers to delegate it to other contracts. Adding an approval system will allow other protocols to build on top of Beanstalk and use transformTokenFrom()

Adding permit implementation to ERC-20 farm balance will allow the Farmer's to delegate their farm balance to other contract in a single transaction which remove the need of submitting a separate transaction and reduce fiction when interacting with Beanstalk.

Specification

Event

event TokenApproval(address indexed owner, address indexed spender, IERC20 token, uint256 amount);

TokenFacet

function transferTokenFrom(
    IERC20 token,
    address sender,
    address recipient,
    uint256 amount,
    LibTransfer.From fromMode,
    LibTransfer.To toMode
) external payable;

function approveToken(
    address spender,
    IERC20 token,
    uint256 amount
) external payable;

function increaseTokenAllowance(
    address spender,
    IERC20 token,
    uint256 addedValue
) public virtual returns (bool);

function decreaseTokenAllowance(
    address spender, 
    IERC20 token,
    uint256 subtractedValue
) public virtual nonReentrant returns (bool);

function tokenAllowance(
    address account, 
    address spender, 
    IERC20 token
) public view virtual returns (uint256);

 function permitToken(
    address owner,
    address spender,
    address token,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
) external payable;

function tokenPermitNonces(address owner)
        public
        view
        virtual
        returns (uint256);

function tokenPermitDomainSeparator() external view returns (bytes32);

LibTokenApprove

function approve(
        address account,
        address spender,
        IERC20 token,
        uint256 amount
    ) internal;

function allowance(
        address account,
        address spender,
        IERC20 token
    ) internal view returns (uint256);

function spendAllowance(
        address owner,
        address spender,
        IERC20 token,
        uint256 amount
    ) internal;

LibTokenPermit

bytes32 private constant TOKEN_PERMIT_HASHED_NAME = keccak256(bytes("Token"));
    bytes32 private constant TOKEN_PERMIT_HASHED_VERSION = keccak256(bytes("1"));
    bytes32 private constant TOKEN_PERMIT_EIP712_TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
    bytes32 private constant TOKEN_PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,address token,uint256 value,uint256 nonce,uint256 deadline)");

function permit(
        address owner,
        address spender,
        address token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal;

LibTransfer

function transferToken(
        IERC20 token,
        address sender,
        address recipient,
        uint256 amount,
        From fromMode,
        To toMode
    ) internal returns (uint256);

Execution

  1. Add & modify functions on TokenFacet
  2. Implement LibTokenPermit library
  3. Implement LibTokenApprove library
  4. Modify LibTransfer to use sender parameter instead of msg.sender
  5. Write tests
  6. Halborn audit
  7. BIP-28
@hellofromguy
Copy link
Contributor

Added in BIP-29: #87

@silochad silochad added the 📜 RFC Formal protocol RFCs label Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📜 RFC Formal protocol RFCs
Projects
None yet
Development

No branches or pull requests

3 participants