Skip to content

Commit

Permalink
EncumbranceSpend event
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-silver committed Jul 17, 2023
1 parent 3c6bcbb commit b1bbca9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/EncumberableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { IERC7246 } from "./interfaces/IERC7246.sol";
* @author Compound
*/
contract EncumberableToken is ERC20, IERC20Permit, IERC7246 {
/**
* @dev Emitted when `taker` spends `amount` of their encumbrance from `owner`
*/
event EncumbranceSpend(address indexed owner, address indexed taker, uint256 previousEncumbrance, uint256 newEncumbrance);

/// @notice The major version of this contract
string public constant VERSION = "1";

Expand Down Expand Up @@ -133,6 +138,7 @@ contract EncumberableToken is ERC20, IERC20Permit, IERC7246 {
uint256 newEncumbrance = currentEncumbrance - amount;
encumbrances[owner][taker] = newEncumbrance;
encumberedBalanceOf[owner] -= amount;
emit EncumbranceSpend(owner, taker, currentEncumbrance, newEncumbrance);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/EncumberableToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EncumberableToken } from "../src/EncumberableToken.sol";
contract EncumberableTokenTest is Test {
event Encumber(address indexed owner, address indexed taker, uint amount);
event Release(address indexed owner, address indexed taker, uint amount);
event EncumbranceSpend(address indexed owner, address indexed taker, uint256 previousEncumbrance, uint256 newEncumbrance);

ERC20 public underlyingToken;
EncumberableToken public wrappedToken;
Expand Down Expand Up @@ -142,6 +143,8 @@ contract EncumberableTokenTest is Test {

// bob calls transfers from alice to charlie
vm.prank(bob);
vm.expectEmit(true, true, true, true);
emit EncumbranceSpend(alice, bob, 60e18, 20e18);
wrappedToken.transferFrom(alice, charlie, 40e18);

// alice balance is reduced
Expand Down

0 comments on commit b1bbca9

Please sign in to comment.