erc20-pool

Permissioned ERC20 swap pool for EVM
Log | Files | Refs | README

commit d244cc05eca4d2d13d63e9e88c1a0ec543eb0726
parent 6d82807ffe112f7e8d3d34e7d4e541be2d0780f8
Author: Mohammed Sohail <sohailsameja@gmail.com>
Date:   Mon,  8 Apr 2024 12:48:27 +0800

feat: add Deposit and Collect events

* refactor public deposit function: the internal function doesn't emit an event when called within withdraw

Diffstat:
Msolidity/SwapPool.sol | 34+++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/solidity/SwapPool.sol b/solidity/SwapPool.sol @@ -38,14 +38,28 @@ contract SwapPool { // Swap event Swap( - address indexed initiator, - address indexed tokenIn, - address tokenOut, - uint256 amountIn, - uint256 amountOut, - uint256 fee + address indexed initiator, + address indexed tokenIn, + address tokenOut, + uint256 amountIn, + uint256 amountOut, + uint256 fee ); + // Deposit + event Deposit( + address indexed initator, + address indexed tokenIn, + uint256 amountIn + ); + + // Collect + event Collect( + address indexed feeAdress, + address tokenOut, + uint256 amountOut + ); + constructor(string memory _name, string memory _symbol, uint8 _decimals, address _tokenRegistry, address _tokenLimiter) { name = _name; symbol = _symbol; @@ -106,6 +120,11 @@ contract SwapPool { } function deposit(address _token, uint256 _value) public { + _deposit(_token, _value); + emit Deposit(msg.sender, _token, _value); + } + + function _deposit(address _token, uint256 _value) private { bool r; bytes memory v; @@ -164,7 +183,7 @@ contract SwapPool { // pool should have enough balance to cover the final outValue (fees already deducted) require(balance >= outValue, "ERR_BALANCE"); - deposit(_inToken, _value); + _deposit(_inToken, _value); (r, v) = _outToken.call(abi.encodeWithSignature('transfer(address,uint256)', msg.sender, outValue)); require(r, "ERR_TOKEN"); @@ -199,6 +218,7 @@ contract SwapPool { r = abi.decode(v, (bool)); require(r, "ERR_TRANSFER"); + emit Collect(feeAddress, _outToken, _value); return _value; }