Skip to content

Commit

Permalink
change access of collect Rubic token and crypto fee to onlyAdmin and …
Browse files Browse the repository at this point in the history
…add recipient param
  • Loading branch information
debych committed Nov 21, 2022
1 parent c225be8 commit 5c3f965
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 6 additions & 4 deletions contracts/BridgeBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,29 @@ contract BridgeBase is AccessControlUpgradeable, PausableUpgradeable, Reentrancy
/**
* @dev Calling this function managers can collect Rubic's token fee
* @param _token The token to collect fees in
* @param _recipient The recipient
*/
function collectRubicFee(address _token) external onlyManagerOrAdmin {
function collectRubicFee(address _token, address _recipient) external onlyAdmin {
uint256 _amount = availableRubicTokenFee[_token];

This comment has been minimized.

Copy link
@grGred

grGred Nov 21, 2022

Contributor

you can add storage pointer for gas, for fun

if (_amount == 0) {
revert ZeroAmount();
}

availableRubicTokenFee[_token] = 0;
sendToken(_token, _amount, msg.sender);
sendToken(_token, _amount, _recipient);

emit RubicTokenFeeCollected(_amount, _token);
}

/**
* @dev Calling this function managers can collect Rubic's fixed crypto fee
* @param _recipient The recipient
*/
function collectRubicCryptoFee() external onlyManagerOrAdmin {
function collectRubicCryptoFee(address _recipient) external onlyAdmin {
uint256 _cryptoFee = availableRubicCryptoFee;
availableRubicCryptoFee = 0;

sendToken(address(0), _cryptoFee, msg.sender);
sendToken(address(0), _cryptoFee, _recipient);

emit FixedCryptoFeeCollected(_cryptoFee, msg.sender);
}
Expand Down
12 changes: 10 additions & 2 deletions test/OnlySourse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,11 @@ describe('TestOnlySource', () => {
expect(await swapToken.balanceOf(integratorWallet.address)).to.be.eq(integratorFee);
});
it('collect Rubic Token fee', async () => {
await bridge.collectRubicFee(swapToken.address);
await expect(
bridge.collectRubicFee(swapToken.address, manager.address)
).to.be.revertedWithCustomError(bridge, 'NotAnAdmin');

await bridge.connect(owner).collectRubicFee(swapToken.address, manager.address);

expect(await swapToken.balanceOf(manager.address)).to.be.eq(RubicFee);
});
Expand All @@ -515,7 +519,11 @@ describe('TestOnlySource', () => {
it('collect Rubic crypto fee', async () => {
const tracker = await balance.tracker(manager.address);

await bridge.collectRubicCryptoFee();
await expect(
bridge.collectRubicCryptoFee(manager.address)
).to.be.revertedWithCustomError(bridge, 'NotAnAdmin');

await bridge.connect(owner).collectRubicCryptoFee(manager.address);

const { delta, fees } = await tracker.deltaWithFees();

Expand Down

0 comments on commit 5c3f965

Please sign in to comment.