add permit

This commit is contained in:
owen05
2020-11-29 23:40:19 +08:00
parent d90e031a30
commit 7290f73634
12 changed files with 602 additions and 18 deletions

View File

@@ -117,11 +117,15 @@ contract DVMVault is DVMStorage {
* @param amount The amount of tokens to be spent.
*/
function approve(address spender, uint256 amount) public returns (bool) {
_ALLOWED_[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
_approve(msg.sender, spender, amount);
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
_ALLOWED_[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Function to check the amount of tokens that an owner _ALLOWED_ to a spender.
* @param owner address The address which owns the funds.
@@ -146,5 +150,21 @@ contract DVMVault is DVMStorage {
emit Transfer(user, address(0), value);
}
// ============================ Permit ======================================
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, 'DODO_DVM_LP: EXPIRED');
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, 'DODO_DVM_LP: INVALID_SIGNATURE');
_approve(owner, spender, value);
}
// ===========================================================================
// function approveAndCall()
}