diff --git a/contracts/HubPool.sol b/contracts/HubPool.sol index c10d7fb4a..7befb9796 100644 --- a/contracts/HubPool.sol +++ b/contracts/HubPool.sol @@ -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); } diff --git a/test/HubPool.Admin.ts b/test/HubPool.Admin.ts index a718e591e..09e431d1d 100644 --- a/test/HubPool.Admin.ts +++ b/test/HubPool.Admin.ts @@ -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;