Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions contracts/HubPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,15 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
* @param l1Token Token to provide liquidity for.
*/
function enableL1TokenForLiquidityProvision(address l1Token) public override onlyOwner nonReentrant {
if (pooledTokens[l1Token].lpToken == address(0))
// If token is being enabled for the first time, create a new LP token and set the timestamp once. We don't
// want to ever reset this timestamp otherwise fees that have accrued will be lost since the last update. This
// could happen for example if an L1 token is enabled, disabled, and then enabled again.
if (pooledTokens[l1Token].lpToken == address(0)) {
pooledTokens[l1Token].lpToken = lpTokenFactory.createLpToken(l1Token);
pooledTokens[l1Token].lastLpFeeUpdate = uint32(getCurrentTime());
}

pooledTokens[l1Token].isEnabled = true;
pooledTokens[l1Token].lastLpFeeUpdate = uint32(getCurrentTime());

emit L1TokenEnabledForLiquidityProvision(l1Token, pooledTokens[l1Token].lpToken);
}
Expand Down
10 changes: 10 additions & 0 deletions test/HubPool.Admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ describe("HubPool Admin functions", function () {
await expect(hubPool.connect(other).enableL1TokenForLiquidityProvision(weth.address)).to.be.reverted;
});
it("Can disable L1 Tokens for liquidity provision", async function () {
await hubPool.enableL1TokenForLiquidityProvision(weth.address);
const pooledTokenStruct = await hubPool.callStatic.pooledTokens(weth.address);
const lpToken = pooledTokenStruct.lpToken;
const lastLpFeeUpdate = pooledTokenStruct.lastLpFeeUpdate;

await hubPool.disableL1TokenForLiquidityProvision(weth.address);
expect((await hubPool.callStatic.pooledTokens(weth.address)).isEnabled).to.equal(false);

// Can re-enable the L1 token now without creating a new LP token or resetting timestamp.
await hubPool.enableL1TokenForLiquidityProvision(weth.address);
expect((await hubPool.callStatic.pooledTokens(weth.address)).lpToken).to.equal(lpToken);
expect((await hubPool.callStatic.pooledTokens(weth.address)).lastLpFeeUpdate).to.equal(lastLpFeeUpdate);
});
it("Only owner can disable L1 Tokens for liquidity provision", async function () {
await expect(hubPool.connect(other).disableL1TokenForLiquidityProvision(weth.address)).to.be.reverted;
Expand Down