Skip to content

Commit

Permalink
Merge pull request #1049 from graphprotocol/fix_oz_n-14
Browse files Browse the repository at this point in the history
fix: emit new events in AuthorizedCollector and TokensRescued. (OZ N-14)
  • Loading branch information
MoonBoi9001 authored Oct 2, 2024
2 parents 31d57b2 + d459928 commit 8be58f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ abstract contract DataServiceRescuable is DataService, IDataServiceRescuable {
if (Denominations.isNativeToken(_token)) Address.sendValue(payable(_to), _tokens);
else SafeERC20.safeTransfer(IERC20(_token), _to, _tokens);

emit TokensRescued(msg.sender, _to, _tokens);
emit TokensRescued(msg.sender, _to, _token, _tokens);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import { IDataService } from "./IDataService.sol";
interface IDataServiceRescuable is IDataService {
/**
* @notice Emitted when tokens are rescued from the contract.
* @param from The address initiating the rescue
* @param to The address receiving the rescued tokens
* @param token The address of the token being rescued
* @param tokens The amount of tokens rescued
*/
event TokensRescued(address indexed from, address indexed to, uint256 tokens);
event TokensRescued(address indexed from, address indexed to, address indexed token, uint256 tokens);

/**
* @notice Emitted when a rescuer is set.
Expand Down
9 changes: 8 additions & 1 deletion packages/horizon/contracts/interfaces/IPaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ interface IPaymentsEscrow {
* @notice Emitted when a payer authorizes a collector to collect funds
* @param payer The address of the payer
* @param collector The address of the collector
* @param addedAllowance The amount of tokens added to the collector's allowance
* @param newTotalAllowance The new total allowance after addition
*/
event AuthorizedCollector(address indexed payer, address indexed collector);
event AuthorizedCollector(
address indexed payer,
address indexed collector,
uint256 addedAllowance,
uint256 newTotalAllowance
);

/**
* @notice Emitted when a payer thaws a collector
Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/contracts/payments/PaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory,
require(allowance != 0, PaymentsEscrowInvalidZeroTokens());
Collector storage collector = authorizedCollectors[msg.sender][collector_];
collector.allowance += allowance;
emit AuthorizedCollector(msg.sender, collector_);
emit AuthorizedCollector(msg.sender, collector_, allowance, collector.allowance);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/horizon/test/escrow/collector.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ contract GraphEscrowCollectorTest is GraphEscrowTest {
function _approveCollector(uint256 tokens) internal {
(uint256 beforeAllowance,) = escrow.authorizedCollectors(users.gateway, users.verifier);
vm.expectEmit(address(escrow));
emit IPaymentsEscrow.AuthorizedCollector(users.gateway, users.verifier);
emit IPaymentsEscrow.AuthorizedCollector(
users.gateway, // payer
users.verifier, // collector
tokens, // addedAllowance
beforeAllowance + tokens // newTotalAllowance after the added allowance
);
escrow.approveCollector(users.verifier, tokens);
(uint256 allowance, uint256 thawEndTimestamp) = escrow.authorizedCollectors(users.gateway, users.verifier);
assertEq(allowance - beforeAllowance, tokens);
Expand Down

0 comments on commit 8be58f9

Please sign in to comment.