Skip to content

Conversation

@chrismaree
Copy link
Member

we need the ability for the protocol to capture fees. This PR adds this and associated unit tests.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
bytes32 destinationDistributionRoot,
bytes32 slowRelayFulfillmentRoot
) public noActiveRequests {
) public nonReentrant noActiveRequests {
Copy link
Member Author

Choose a reason for hiding this comment

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

modifiers were missing.

// Interest rate payment that scales the amount of pending fees per second paid to LPs. 0.0000015e18 will pay out
// the full amount of fees entitled to LPs in ~ 7.72 days, just over the standard L2 7 day liveness.
uint256 lpFeeRatePerSecond = 1500000000000;
uint256 public lpFeeRatePerSecond = 1500000000000;
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be public.

Copy link
Member

Choose a reason for hiding this comment

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

can we make this uint64 to match the other pcts?

@@ -1,108 +0,0 @@
import { toWei, toBNWei, SignerWithAddress, seedWallet, expect, Contract, ethers } from "./utils";
Copy link
Member Author

Choose a reason for hiding this comment

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

this file was a dup of the HubPool HubPool.LiquidityProvisionFees.ts

// Create an action that will send an L1->L2 tokens transfer and bundle. For this, create a relayer repayment bundle
// and check that at it's finalization the L2 bridge contracts are called as expected.
const { leafs, tree, tokensSendToL2 } = await constructSingleChainTree(dai, 1, arbitrumChainId);
await hubPool.connect(dataWorker).initiateRelayerRefund([3117], 1, tree.getHexRoot(), consts.mockTreeRoot);
Copy link
Member Author

Choose a reason for hiding this comment

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

there was a merge issue from the previous PR. this is unrelated to the main change.

address public protocolFeeCaptureAddress;

// Percentage of lpFees that are captured by the protocol and claimable by the protocolFeeCaptureAddress.
uint256 public protocolFeeCapturePct;
Copy link
Member

Choose a reason for hiding this comment

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

Same, should change to uint64

Copy link
Contributor

@mrice32 mrice32 Feb 14, 2022

Choose a reason for hiding this comment

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

Can we also put all the uint64 variables next to one another to decrease the cost of reading? Ideally, if we're smart about it, we can group variables that are often read (or written) in the same txn to reduce the overall number of words read/written.

* ADMIN FUNCTIONS *
*************************************************/

function setProtocolFeeCaptureAddress(address newProtocolFeeCaptureAddress) public onlyOwner {
Copy link
Member

Choose a reason for hiding this comment

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

Should this function logic be collapsed with the following one?

Copy link
Member Author

Choose a reason for hiding this comment

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

ye, good point. can do how we do the setBond method.

}

function claimProtocolFeesCaptured(address l1Token) public nonReentrant {
if (unclaimedAccumulatedProtocolFees[l1Token] > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

do we need this check..? whats the harm of sending 0, the caller will jsut pay gas

Copy link
Member Author

Choose a reason for hiding this comment

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

it's cheaper. it's just for gas optimisation.

I agree with you though that in this context we can remove this. In the context of the fee allocation I think it's better to keep this to remove gas usage.

chrismaree and others added 3 commits February 14, 2022 14:07
Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

LGTM! A few minor nits

address public protocolFeeCaptureAddress;

// Percentage of lpFees that are captured by the protocol and claimable by the protocolFeeCaptureAddress.
uint256 public protocolFeeCapturePct;
Copy link
Contributor

@mrice32 mrice32 Feb 14, 2022

Choose a reason for hiding this comment

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

Can we also put all the uint64 variables next to one another to decrease the cost of reading? Ideally, if we're smart about it, we can group variables that are often read (or written) in the same txn to reduce the overall number of words read/written.

onlyOwner
{
protocolFeeCaptureAddress = newProtocolFeeCaptureAddress;
protocolFeeCapturePct = newProtocolFeeCapturePct;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check that this is <= 1e18?

Comment on lines 631 to 632
pooledTokens[l1Token].undistributedLpFees += lpFeesCaptured;
pooledTokens[l1Token].utilizedReserves += int256(lpFeesCaptured);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we wrap this in if (lpFeesCaptured > 0)?

Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree merged commit 15bc2c2 into master Feb 15, 2022
@chrismaree chrismaree deleted the chrismaree/fee-knob branch February 15, 2022 21:40
pxrl pushed a commit that referenced this pull request Feb 20, 2024
pxrl pushed a commit that referenced this pull request Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants