Skip to content

Commit

Permalink
adjust sample implementation to match interface
Browse files Browse the repository at this point in the history
  • Loading branch information
coburncoburn committed Jun 28, 2023
1 parent c50f62a commit 23df83a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions EIPS/eip-7246.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ interface IERC7246{
*
* Emits a {Release} event.
*/
function release(address owner, uint amount);
function release(address owner, uint amount) external;
/**
* @dev Convenience function for reading the unencumbered balance of an address.
* Trivially implemented as `balanceOf(owner) - encumberedBalanceOf(owner)`
*/
function availableBalanceOf(address owner) external returns (uint);
function availableBalanceOf(address owner) public view returns (uint);
}
```

Expand Down Expand Up @@ -123,7 +123,7 @@ contract EncumberableERC20 is ERC20 {
// The encumbered balance of the token owner. encumberedBalance must not exceed balanceOf for a user
// Note this means rebasing tokens pose a risk of diminishing and violating this prototocol
mapping (address => uint) public encumberedBalance;
mapping (address => uint) public encumberedBalanceOf;
address public minter;
Expand All @@ -140,25 +140,22 @@ contract EncumberableERC20 is ERC20 {
return true;
}
function encumber(address taker, uint amount) public virtual returns (bool) {
function encumber(address taker, uint amount) external {
_encumber(msg.sender, taker, amount);
return true;
}
function encumberFrom(address owner, address taker, uint amount) public virtual returns (bool) {
function encumberFrom(address owner, address taker, uint amount) external {
require(allowance(owner, msg.sender) >= amount);
_encumber(owner, taker, amount);
return true;
}
function release(address owner, uint amount) public virtual returns (bool) {
function release(address owner, uint amount) external {
_release(owner, msg.sender, amount);
return true;
}
// If bringing balance and encumbrances closer to equal, must check
function availableBalanceOf(address a) public view returns (uint) {
return (balanceOf(a) - encumberedBalance[a]);
return (balanceOf[a] - encumberedBalanceOf[a]);
}
function _encumber(address owner, address taker, uint amount) private {
Expand Down Expand Up @@ -212,7 +209,7 @@ contract EncumberableERC20 is ERC20 {
require(currentEncumbrance >= amount, "insufficient encumbrance");
uint newEncumbrance = currentEncumbrance - amount;
encumbrances[owner][taker] = newEncumbrance;
encumberedBalance[owner] -= amount;
encumberedBalanceOf[owner] -= amount;
}
}
```
Expand Down

0 comments on commit 23df83a

Please sign in to comment.