Skip to content

Commit

Permalink
tob I04: add donate event (#845)
Browse files Browse the repository at this point in the history
* add donate event

* fix snapshots
  • Loading branch information
snreynolds authored Aug 26, 2024
1 parent 4e42121 commit a4b28e3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 1 token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104429
106488
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 2 tokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144017
146076
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24354
24404
6 changes: 5 additions & 1 deletion src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim
noDelegateCall
returns (BalanceDelta delta)
{
Pool.State storage pool = _getPool(key.toId());
PoolId poolId = key.toId();
Pool.State storage pool = _getPool(poolId);
pool.checkPoolInitialized();

key.hooks.beforeDonate(key, amount0, amount1, hookData);
Expand All @@ -262,6 +263,9 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim

_accountPoolBalanceDelta(key, delta, msg.sender);

// event is emitted before the afterDonate call to ensure events are always emitted in order
emit Donate(poolId, msg.sender, amount0, amount1);

key.hooks.afterDonate(key, amount0, amount1, hookData);
}

Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/IPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ interface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload {
uint24 fee
);

/// @notice Emitted for donations
/// @param id The abi encoded hash of the pool key struct for the pool that was donated to
/// @param sender The address that initiated the donate call
/// @param amount0 The amount donated in currency0
/// @param amount1 The amount donated in currency1
event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);

/// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement
/// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract.
/// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`
Expand Down
11 changes: 11 additions & 0 deletions test/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
uint24 fee
);

event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);

event Transfer(
address caller, address indexed sender, address indexed receiver, uint256 indexed id, uint256 amount
);
Expand Down Expand Up @@ -876,6 +878,15 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
snapLastCall("donate gas with 1 token");
}

function test_fuzz_donate_emits_event(uint256 amount0, uint256 amount1) public {
amount0 = bound(amount0, 0, uint256(int256(type(int128).max)));
amount1 = bound(amount1, 0, uint256(int256(type(int128).max)));

vm.expectEmit(true, true, false, true, address(manager));
emit Donate(key.toId(), address(donateRouter), uint256(amount0), uint256(amount1));
donateRouter.donate(key, amount0, amount1, ZERO_BYTES);
}

function test_take_failsWithNoLiquidity() public {
deployFreshManagerAndRouters();

Expand Down

0 comments on commit a4b28e3

Please sign in to comment.