Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Send claimed market fees to factory owner #79

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/perennial/contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ contract Market is IMarket, Instance, ReentrancyGuard {
_global.store(newGlobal);
}

/// @notice Helper function to handle a singular fee claim
/// @notice Helper function to handle a singular fee claim. If the factory is claiming, sends the fee to the
/// factory owner.
/// @param receiver The address to receive the fee
/// @param fee The amount of the fee to claim
function _claimFee(address receiver, UFixed6 fee) private returns (bool) {
if (msg.sender != receiver) return false;
if (msg.sender == address(factory())) receiver = factory().owner();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should just pass in factory().owner() in the above method instead, in the protocolFee clause

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - then should we also remove the fund method in the Factory since it's not longer possible to use it to claim the fees?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good catch let's remove that too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


token.push(receiver, UFixed18Lib.from(fee));
emit FeeClaimed(receiver, fee);
Expand Down
4 changes: 2 additions & 2 deletions packages/perennial/test/unit/market/Market.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13054,11 +13054,11 @@ describe('Market', () => {
})

it('claims fee (protocol)', async () => {
dsu.transfer.whenCalledWith(factory.address, PROTOCOL_FEE.mul(1e12)).returns(true)
dsu.transfer.whenCalledWith(owner.address, PROTOCOL_FEE.mul(1e12)).returns(true)

await expect(market.connect(factorySigner).claimFee())
.to.emit(market, 'FeeClaimed')
.withArgs(factory.address, PROTOCOL_FEE)
.withArgs(owner.address, PROTOCOL_FEE)

expect((await market.global()).protocolFee).to.equal(0)
expect((await market.global()).oracleFee).to.equal(ORACLE_FEE)
Expand Down