Skip to content

Commit d604858

Browse files
committed
Refactor
1 parent 82d5db9 commit d604858

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

packages/v3/contracts/pools/PoolCollection.sol

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ contract PoolCollection is IPoolCollection, OwnedUpgradeable, ReentrancyGuardUpg
4242

4343
uint32 private constant DEFAULT_TRADING_FEE_PPM = 2000; // 0.2%
4444

45+
// trading enabling/disabling reasons
46+
uint8 private constant TRADING_ENABLED_BY_OWNER = 0;
47+
uint8 private constant TRADING_ENABLED_BY_MINIMUM_LIQUIDITY = 1;
48+
4549
// withdrawal-related input data
4650
struct PoolWithdrawalParams {
4751
uint256 networkTokenAvgTradingLiquidity;
@@ -101,15 +105,10 @@ contract PoolCollection is IPoolCollection, OwnedUpgradeable, ReentrancyGuardUpg
101105
*/
102106
event TradingFeePPMUpdated(IReserveToken indexed pool, uint32 prevFeePPM, uint32 newFeePPM);
103107

104-
enum TradingEnablingReason {
105-
Owner,
106-
MinmumLiquidity
107-
}
108-
109108
/**
110109
* @dev triggered when trading in a specific pool is enabled/disabled
111110
*/
112-
event TradingEnabled(IReserveToken indexed pool, bool newStatus, TradingEnablingReason reason);
111+
event TradingEnabled(IReserveToken indexed pool, bool newStatus, uint8 reason);
113112

114113
/**
115114
* @dev triggered when depositing to a specific pool is enabled/disabled
@@ -262,7 +261,7 @@ contract PoolCollection is IPoolCollection, OwnedUpgradeable, ReentrancyGuardUpg
262261

263262
// although the owner-controlled flag is set to true, we want to emphasize that the trading in a newly created
264263
// pool is disabled
265-
emit TradingEnabled({ pool: reserveToken, newStatus: false, reason: TradingEnablingReason.Owner });
264+
emit TradingEnabled({ pool: reserveToken, newStatus: false, reason: TRADING_ENABLED_BY_OWNER });
266265

267266
emit TradingFeePPMUpdated({ pool: reserveToken, prevFeePPM: 0, newFeePPM: newPool.tradingFeePPM });
268267
emit DepositingEnabled({ pool: reserveToken, newStatus: newPool.depositingEnabled });
@@ -349,7 +348,7 @@ contract PoolCollection is IPoolCollection, OwnedUpgradeable, ReentrancyGuardUpg
349348

350349
poolData.tradingEnabled = status;
351350

352-
emit TradingEnabled({ pool: pool, newStatus: status, reason: TradingEnablingReason.Owner });
351+
emit TradingEnabled({ pool: pool, newStatus: status, reason: TRADING_ENABLED_BY_OWNER });
353352
}
354353

355354
/**
@@ -462,7 +461,7 @@ contract PoolCollection is IPoolCollection, OwnedUpgradeable, ReentrancyGuardUpg
462461
poolData.liquidity.networkTokenTradingLiquidity.add(depositParams.baseTokenDeltaAmount) >=
463462
minLiquidityForTrading
464463
) {
465-
emit TradingEnabled({ pool: pool, newStatus: true, reason: TradingEnablingReason.MinmumLiquidity });
464+
emit TradingEnabled({ pool: pool, newStatus: true, reason: TRADING_ENABLED_BY_MINIMUM_LIQUIDITY });
466465
}
467466
}
468467

@@ -695,7 +694,7 @@ contract PoolCollection is IPoolCollection, OwnedUpgradeable, ReentrancyGuardUpg
695694
emit TradingEnabled({
696695
pool: pool,
697696
newStatus: newEnabled,
698-
reason: TradingEnablingReason.MinmumLiquidity
697+
reason: TRADING_ENABLED_BY_MINIMUM_LIQUIDITY
699698
});
700699
}
701700
}

packages/v3/test/pools/PoolCollection.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ import { ethers } from 'hardhat';
1313
import path from 'path';
1414

1515
describe('PoolCollection', () => {
16-
enum TradingEnablingReason {
17-
Owner = 0,
18-
MinLiquidity = 1
19-
}
20-
2116
const DEFAULT_TRADING_FEE_PPM = BigNumber.from(2000);
2217
const POOL_TYPE = BigNumber.from(1);
2318
const SYMBOL = 'TKN';
2419
const MIN_LIQUIDITY_FOR_TRADING = toWei(BigNumber.from(100_000));
2520
const INITIAL_RATE = { n: BigNumber.from(1), d: BigNumber.from(2) };
2621

22+
const TRADING_ENABLED_BY_OWNER = 0;
23+
const TRADING_ENABLED_BY_MINIMUM_LIQUIDITY = 1;
24+
2725
let deployer: SignerWithAddress;
2826
let nonOwner: SignerWithAddress;
2927

@@ -192,7 +190,7 @@ describe('PoolCollection', () => {
192190
.withArgs(reserveToken.address, BigNumber.from(0), pool.tradingFeePPM);
193191
await expect(res)
194192
.to.emit(poolCollection, 'TradingEnabled')
195-
.withArgs(reserveToken.address, false, TradingEnablingReason.Owner);
193+
.withArgs(reserveToken.address, false, TRADING_ENABLED_BY_OWNER);
196194
await expect(res)
197195
.to.emit(poolCollection, 'DepositingEnabled')
198196
.withArgs(reserveToken.address, pool.depositingEnabled);
@@ -406,7 +404,7 @@ describe('PoolCollection', () => {
406404
const res = await poolCollection.enableTrading(reserveToken.address, false);
407405
await expect(res)
408406
.to.emit(poolCollection, 'TradingEnabled')
409-
.withArgs(reserveToken.address, false, TradingEnablingReason.Owner);
407+
.withArgs(reserveToken.address, false, TRADING_ENABLED_BY_OWNER);
410408

411409
pool = await poolCollection.poolData(reserveToken.address);
412410
({ tradingEnabled } = pool);
@@ -415,7 +413,7 @@ describe('PoolCollection', () => {
415413
const res2 = await poolCollection.enableTrading(reserveToken.address, true);
416414
await expect(res2)
417415
.to.emit(poolCollection, 'TradingEnabled')
418-
.withArgs(reserveToken.address, true, TradingEnablingReason.Owner);
416+
.withArgs(reserveToken.address, true, TRADING_ENABLED_BY_OWNER);
419417

420418
pool = await poolCollection.poolData(reserveToken.address);
421419
({ tradingEnabled } = pool);
@@ -1000,7 +998,7 @@ describe('PoolCollection', () => {
1000998
) {
1001999
await expect(res)
10021000
.to.emit(poolCollection, 'TradingEnabled')
1003-
.withArgs(reserveToken.address, true, TradingEnablingReason.MinLiquidity);
1001+
.withArgs(reserveToken.address, true, TRADING_ENABLED_BY_MINIMUM_LIQUIDITY);
10041002
}
10051003

10061004
let rate;

0 commit comments

Comments
 (0)