Skip to content

Commit

Permalink
Add events to FungibleTokenWrapper and TokenWrapper for wrapping/unwr…
Browse files Browse the repository at this point in the history
…apping/parameter updates
  • Loading branch information
drewstone committed Jul 6, 2023
1 parent a8344e2 commit 92f74b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/contracts/contracts/tokens/FungibleTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ contract FungibleTokenWrapper is
uint256 public wrappingLimit;

event HandlerUpdated(address _handler);
event NativeAllowed(bool _isNativeAllowed);
event TokenAdded(address _tokenAddress);
event TokenRemoved(address _tokenAddress);
event FeeUpdated(uint16 _feePercentage);
event FeeRecipientUpdated(address _feeRecipient);
event WrappingLimitUpdated(uint256 _limit);

/// @notice FungibleTokenWrapper constructor
/// @param _name The name of the ERC20 TokenWrapper
Expand Down Expand Up @@ -82,6 +88,7 @@ contract FungibleTokenWrapper is
/// @notice Only the handler can call this function
function setNativeAllowed(bool _isNativeAllowed) public onlyHandler {
isNativeAllowed = _isNativeAllowed;
emit NativeAllowed(_isNativeAllowed);
}

/// @notice Adds a token at `_tokenAddress` to the FungibleTokenWrapper's wrapping list
Expand All @@ -100,6 +107,7 @@ contract FungibleTokenWrapper is
historicallyValid[_tokenAddress] = true;
}
valid[_tokenAddress] = true;
emit TokenAdded(_tokenAddress);
}

/// @notice Removes a token at `_tokenAddress` from the FungibleTokenWrapper's wrapping list
Expand All @@ -121,6 +129,7 @@ contract FungibleTokenWrapper is
require(index < tokens.length, "FungibleTokenWrapper: Token not found");
valid[_tokenAddress] = false;
removeTokenAtIndex(index);
emit TokenRemoved(_tokenAddress);
}

/// @notice Sets a new `_feePercentage` for the FungibleTokenWrapper
Expand All @@ -133,6 +142,7 @@ contract FungibleTokenWrapper is
) external override onlyHandler onlyIncrementingByOne(_nonce) {
require(_feePercentage < 10_000, "FungibleTokenWrapper: Invalid fee percentage");
feePercentage = _feePercentage;
emit FeeUpdated(_feePercentage);
}

/// @notice Sets a new `_feeRecipient` for the FungibleTokenWrapper
Expand All @@ -148,6 +158,7 @@ contract FungibleTokenWrapper is
"FungibleTokenWrapper: Fee Recipient cannot be zero address"
);
feeRecipient = _feeRecipient;
emit FeeRecipientUpdated(_feeRecipient);
}

/// @notice Removes a token at `_index` from the FungibleTokenWrapper's wrapping list
Expand All @@ -162,6 +173,7 @@ contract FungibleTokenWrapper is
/// @notice Only the handler can call this function
function updateLimit(uint256 _limit) public onlyHandler {
wrappingLimit = _limit;
emit WrappingLimitUpdated(_limit);
}

/// @notice Gets the current fee percentage
Expand Down
21 changes: 21 additions & 0 deletions packages/contracts/contracts/tokens/TokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ abstract contract TokenWrapper is ERC20PresetMinterPauser, ITokenWrapper, Reentr
uint16 public feePercentage;
address payable public feeRecipient;

event Wrapping(
address indexed sender,
address indexed recipient,
address indexed tokenAddress,
uint256 wrappingFee,
uint256 afterFeeAmount
);

event Unwrapping(
address indexed sender,
address indexed recipient,
address indexed tokenAddress,
uint256 amount
);

/// @notice TokenWrapper constructor
/// @param _name The name of the ERC20
/// @param _symbol The symbol of the ERC20
Expand Down Expand Up @@ -162,6 +177,9 @@ abstract contract TokenWrapper is ERC20PresetMinterPauser, ITokenWrapper, Reentr
}
// mint the wrapped token for the recipient
_mint(recipient, leftover);

// Emit the wrapping event
emit Wrapping(sender, recipient, tokenAddress, costToWrap, leftover);
}

function _unwrapAndSendTo(
Expand All @@ -180,6 +198,9 @@ abstract contract TokenWrapper is ERC20PresetMinterPauser, ITokenWrapper, Reentr
// transfer ERC20 liquidity from the token wrapper to the sender
IERC20(tokenAddress).safeTransfer(recipient, amount);
}

// Emit the unwrapping event
emit Unwrapping(sender, recipient, tokenAddress, amount);
}

/// @dev this function is defined in a child contract
Expand Down

0 comments on commit 92f74b5

Please sign in to comment.