Skip to content

Commit 7654517

Browse files
committed
feat: code dump
In this commit: - factories upgradability - versioning - some roles management - small fixes and improvements here and there
1 parent 5464ebf commit 7654517

24 files changed

+606
-395
lines changed

.DS_Store

-6 KB
Binary file not shown.

contracts/factories/AbstractFactory.sol

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract contract AbstractFactory is AbstractDeployer, IFactory {
3636
// ----------- //
3737

3838
constructor(address addressProvider_) AbstractDeployer(addressProvider_) {
39-
marketConfiguratorFactory = _getContract(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL);
39+
marketConfiguratorFactory = _getAddressOrRevert(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL);
4040
}
4141

4242
// ------------- //
@@ -79,17 +79,25 @@ abstract contract AbstractFactory is AbstractDeployer, IFactory {
7979
});
8080
}
8181

82-
function _addToAccessList(address marketConfigurator, address target) internal view returns (Call memory) {
82+
function _authorizeFactory(address marketConfigurator, address suite, address target)
83+
internal
84+
view
85+
returns (Call memory)
86+
{
8387
return Call({
8488
target: marketConfigurator,
85-
callData: abi.encodeCall(IMarketConfigurator.addToAccessList, (target, address(this)))
89+
callData: abi.encodeCall(IMarketConfigurator.authorizeFactory, (address(this), suite, target))
8690
});
8791
}
8892

89-
function _removeFromAccessList(address marketConfigurator, address target) internal view returns (Call memory) {
93+
function _unauthorizeFactory(address marketConfigurator, address suite, address target)
94+
internal
95+
view
96+
returns (Call memory)
97+
{
9098
return Call({
9199
target: marketConfigurator,
92-
callData: abi.encodeCall(IMarketConfigurator.removeFromAccessList, (target, address(this)))
100+
callData: abi.encodeCall(IMarketConfigurator.unauthorizeFactory, (address(this), suite, target))
93101
});
94102
}
95103
}

contracts/factories/AbstractMarketFactory.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ abstract contract AbstractMarketFactory is AbstractFactory, IMarketFactory {
8787
return IPoolQuotaKeeperV3(quotaKeeper).gauge();
8888
}
8989

90+
function _quotedTokens(address quotaKeeper) internal view returns (address[] memory) {
91+
return IPoolQuotaKeeperV3(quotaKeeper).quotedTokens();
92+
}
93+
9094
function _isQuotedToken(address quotaKeeper, address token) internal view returns (bool) {
9195
return IPoolQuotaKeeperV3(quotaKeeper).isQuotedToken(token);
9296
}

contracts/factories/CreditFactory.sol

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
9292
/// @param addressProvider_ Address provider contract address
9393
constructor(address addressProvider_) AbstractFactory(addressProvider_) {
9494
// TODO: introduce some kind of `StuffRegister` for account factories, bot lists and degen NFTs
95-
weth = _tryGetContract(AP_WETH_TOKEN, NO_VERSION_CONTROL);
95+
weth = _tryGetAddress(AP_WETH_TOKEN, NO_VERSION_CONTROL);
9696
}
9797

9898
// ---------- //
@@ -121,8 +121,8 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
121121
return DeployResult({
122122
newContract: creditManager,
123123
onInstallOps: CallBuilder.build(
124-
_addToAccessList(msg.sender, creditConfigurator),
125-
_addToAccessList(msg.sender, creditFacade),
124+
_authorizeFactory(msg.sender, creditManager, creditConfigurator),
125+
_authorizeFactory(msg.sender, creditManager, creditFacade),
126126
_setCreditFacade(creditConfigurator, creditFacade, false),
127127
_setLossLiquidator(creditConfigurator, lossLiquidator),
128128
_setDebtLimits(creditConfigurator, params.minDebt, params.maxDebt)
@@ -168,28 +168,30 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
168168
address newCreditConfigurator = _deployCreditConfigurator(msg.sender, creditManager);
169169
return CallBuilder.build(
170170
_upgradeCreditConfigurator(creditConfigurator, newCreditConfigurator),
171-
_removeFromAccessList(msg.sender, creditConfigurator),
172-
_addToAccessList(msg.sender, newCreditConfigurator)
171+
_unauthorizeFactory(msg.sender, creditManager, creditConfigurator),
172+
_authorizeFactory(msg.sender, creditManager, newCreditConfigurator)
173173
);
174174
} else if (selector == IConfigureActions.upgradeCreditFacade.selector) {
175175
CreditFacadeParams memory params = abi.decode(callData[4:], (CreditFacadeParams));
176176
address creditFacade = _creditFacade(creditManager);
177177
address newCreditFacade = _deployCreditFacade(msg.sender, creditManager, params);
178178
return CallBuilder.build(
179179
_setCreditFacade(_creditConfigurator(creditManager), newCreditFacade, true),
180-
_removeFromAccessList(msg.sender, creditFacade),
181-
_addToAccessList(msg.sender, newCreditFacade)
180+
_unauthorizeFactory(msg.sender, creditManager, creditFacade),
181+
_authorizeFactory(msg.sender, creditManager, newCreditFacade)
182182
);
183183
} else if (selector == IConfigureActions.allowAdapter.selector) {
184184
DeployParams memory params = abi.decode(callData[4:], (DeployParams));
185185
address adapter = _deployAdapter(msg.sender, creditManager, params);
186186
return CallBuilder.build(
187-
_addToAccessList(msg.sender, adapter), _allowAdapter(_creditConfigurator(creditManager), adapter)
187+
_authorizeFactory(msg.sender, creditManager, adapter),
188+
_allowAdapter(_creditConfigurator(creditManager), adapter)
188189
);
189190
} else if (selector == IConfigureActions.forbidAdapter.selector) {
190191
address adapter = abi.decode(callData[4:], (address));
191192
return CallBuilder.build(
192-
_removeFromAccessList(msg.sender, adapter), _forbidAdapter(_creditConfigurator(creditManager), adapter)
193+
_authorizeFactory(msg.sender, creditManager, adapter),
194+
_forbidAdapter(_creditConfigurator(creditManager), adapter)
193195
);
194196
} else if (
195197
selector == IConfigureActions.setFees.selector
@@ -217,7 +219,8 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
217219
if (selector == IEmergencyConfigureActions.forbidAdapter.selector) {
218220
address adapter = abi.decode(callData[4:], (address));
219221
return CallBuilder.build(
220-
_removeFromAccessList(msg.sender, adapter), _forbidAdapter(_creditConfigurator(creditManager), adapter)
222+
_unauthorizeFactory(msg.sender, creditManager, adapter),
223+
_forbidAdapter(_creditConfigurator(creditManager), adapter)
221224
);
222225
} else if (
223226
selector == IEmergencyConfigureActions.forbidBorrowing.selector
@@ -257,10 +260,9 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
257260
params.name
258261
);
259262

260-
return _deployByDomain({
261-
domain: DOMAIN_CREDIT_MANAGER,
262-
postfix: postfix,
263-
version: version,
263+
return _deployLatestPatch({
264+
contractType: _getContractType(DOMAIN_CREDIT_MANAGER, postfix),
265+
minorVersion: version,
264266
constructorParams: constructorParams,
265267
salt: bytes32(bytes20(marketConfigurator))
266268
});
@@ -269,9 +271,9 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
269271
function _deployCreditConfigurator(address marketConfigurator, address creditManager) internal returns (address) {
270272
bytes memory constructorParams = abi.encode(creditManager);
271273

272-
return _deploy({
274+
return _deployLatestPatch({
273275
contractType: AP_CREDIT_CONFIGURATOR,
274-
version: version,
276+
minorVersion: version,
275277
constructorParams: constructorParams,
276278
salt: bytes32(bytes20(marketConfigurator))
277279
});
@@ -287,9 +289,9 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
287289
bytes memory constructorParams =
288290
abi.encode(acl, creditManager, params.botList, weth, params.degenNFT, params.expirable);
289291

290-
return _deploy({
292+
return _deployLatestPatch({
291293
contractType: AP_CREDIT_FACADE,
292-
version: version,
294+
minorVersion: version,
293295
constructorParams: constructorParams,
294296
salt: bytes32(bytes20(marketConfigurator))
295297
});
@@ -304,10 +306,9 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
304306

305307
// NOTE: unlike other contracts, this might be deployed multiple times, so using the same salt
306308
// can be an issue. Same thing can happen to rate keepers, IRMs, etc.
307-
return _deployByDomain({
308-
domain: DOMAIN_ADAPTER,
309-
postfix: params.postfix,
310-
version: version,
309+
return _deployLatestPatch({
310+
contractType: _getContractType(DOMAIN_ADAPTER, params.postfix),
311+
minorVersion: version,
311312
constructorParams: params.constructorParams,
312313
salt: bytes32(bytes20(marketConfigurator))
313314
});
@@ -361,22 +362,6 @@ contract CreditFactory is AbstractFactory, ICreditFactory {
361362
return Call(creditConfigurator, abi.encodeCall(ICreditConfiguratorV3.forbidAdapter, adapter));
362363
}
363364

364-
function _setFees(
365-
address creditConfigurator,
366-
uint16 feeLiquidation,
367-
uint16 liquidationPremium,
368-
uint16 feeLiquidationExpired,
369-
uint16 liquidationPremiumExpired
370-
) internal pure returns (Call memory) {
371-
return Call(
372-
creditConfigurator,
373-
abi.encodeCall(
374-
ICreditConfiguratorV3.setFees,
375-
(feeLiquidation, liquidationPremium, feeLiquidationExpired, liquidationPremiumExpired)
376-
)
377-
);
378-
}
379-
380365
function _setDebtLimits(address creditConfigurator, uint128 minDebt, uint128 maxDebt)
381366
internal
382367
pure

contracts/factories/InterestRateModelFactory.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,24 @@ contract InterestRateModelFactory is AbstractMarketFactory, IInterestRateModelFa
4141
_validateDefaultConstructorParams(pool, params.constructorParams);
4242
}
4343

44-
address interestRateModel = _deployByDomain({
45-
domain: DOMAIN_IRM,
46-
postfix: params.postfix,
47-
version: version,
44+
address interestRateModel = _deployLatestPatch({
45+
contractType: _getContractType(DOMAIN_IRM, params.postfix),
46+
minorVersion: version,
4847
constructorParams: params.constructorParams,
4948
salt: bytes32(bytes20(msg.sender))
5049
});
5150

5251
return DeployResult({
5352
newContract: interestRateModel,
54-
onInstallOps: CallBuilder.build(_addToAccessList(msg.sender, interestRateModel))
53+
onInstallOps: CallBuilder.build(_authorizeFactory(msg.sender, pool, interestRateModel))
5554
});
5655
}
5756

5857
// ------------ //
5958
// MARKET HOOKS //
6059
// ------------ //
6160

62-
function onUpdateInterestRateModel(address, address newInterestRateModel, address oldInterestRateModel)
61+
function onUpdateInterestRateModel(address pool, address newInterestRateModel, address oldInterestRateModel)
6362
external
6463
view
6564
override(AbstractMarketFactory, IMarketFactory)
@@ -71,6 +70,8 @@ contract InterestRateModelFactory is AbstractMarketFactory, IInterestRateModelFa
7170
if (_isVotingContract(newInterestRateModel)) {
7271
calls = calls.append(_setVotingContractStatus(newInterestRateModel, true));
7372
}
73+
74+
calls = calls.append(_unauthorizeFactory(msg.sender, pool, oldInterestRateModel));
7475
}
7576

7677
// ------------- //

contracts/factories/LossLiquidatorFactory.sol

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pragma solidity ^0.8.23;
55

66
import {IFactory} from "../interfaces/factories/IFactory.sol";
7+
import {IMarketFactory} from "../interfaces/factories/IMarketFactory.sol";
78
import {ILossLiquidatorFactory} from "../interfaces/factories/ILossLiquidatorFactory.sol";
89
import {Call, DeployParams, DeployResult} from "../interfaces/Types.sol";
910

@@ -41,20 +42,32 @@ contract LossLiquidatorFactory is AbstractMarketFactory, ILossLiquidatorFactory
4142
_validateDefaultConstructorParams(pool, params.constructorParams);
4243
}
4344

44-
address lossLiquidator = _deployByDomain({
45-
domain: DOMAIN_LOSS_LIQUIDATOR,
46-
postfix: params.postfix,
47-
version: version,
45+
address lossLiquidator = _deployLatestPatch({
46+
contractType: _getContractType(DOMAIN_LOSS_LIQUIDATOR, params.postfix),
47+
minorVersion: version,
4848
constructorParams: params.constructorParams,
4949
salt: bytes32(bytes20(msg.sender))
5050
});
5151

5252
return DeployResult({
5353
newContract: lossLiquidator,
54-
onInstallOps: CallBuilder.build(_addToAccessList(msg.sender, lossLiquidator))
54+
onInstallOps: CallBuilder.build(_authorizeFactory(msg.sender, pool, lossLiquidator))
5555
});
5656
}
5757

58+
// ------------ //
59+
// MARKET HOOKS //
60+
// ------------ //
61+
62+
function onUpdateLossLiquidator(address pool, address, address oldLossLiquidator)
63+
external
64+
view
65+
override(AbstractMarketFactory, IMarketFactory)
66+
returns (Call[] memory calls)
67+
{
68+
calls = CallBuilder.build(_unauthorizeFactory(msg.sender, pool, oldLossLiquidator));
69+
}
70+
5871
// ------------- //
5972
// CONFIGURATION //
6073
// ------------- //

contracts/factories/PoolFactory.sol

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ contract PoolFactory is AbstractMarketFactory, IPoolFactory {
7373
/// @notice Constructor
7474
/// @param addressProvider_ Address provider contract address
7575
constructor(address addressProvider_) AbstractFactory(addressProvider_) {
76-
defaultInterestRateModel = _getContract(AP_DEFAULT_IRM, NO_VERSION_CONTROL);
76+
defaultInterestRateModel = _getAddressOrRevert(AP_DEFAULT_IRM, NO_VERSION_CONTROL);
7777
}
7878

7979
// ---------- //
@@ -97,8 +97,8 @@ contract PoolFactory is AbstractMarketFactory, IPoolFactory {
9797
return DeployResult({
9898
newContract: pool,
9999
onInstallOps: CallBuilder.build(
100-
_addToAccessList(msg.sender, pool),
101-
_addToAccessList(msg.sender, quotaKeeper),
100+
_authorizeFactory(msg.sender, pool, pool),
101+
_authorizeFactory(msg.sender, pool, quotaKeeper),
102102
_setQuotaKeeper(pool, quotaKeeper)
103103
)
104104
});
@@ -246,19 +246,18 @@ contract PoolFactory is AbstractMarketFactory, IPoolFactory {
246246
acl, contractsRegister, underlying, treasury, defaultInterestRateModel, type(uint256).max, name, symbol
247247
);
248248
bytes32 salt = bytes32(bytes20(marketConfigurator));
249-
return _deployByDomain({
250-
domain: DOMAIN_POOL,
251-
postfix: postfix,
252-
version: version,
249+
return _deployLatestPatch({
250+
contractType: _getContractType(DOMAIN_POOL, postfix),
251+
minorVersion: version,
253252
constructorParams: constructorParams,
254253
salt: salt
255254
});
256255
}
257256

258257
function _deployQuotaKeeper(address marketConfigurator, address pool) internal returns (address) {
259-
return _deploy({
258+
return _deployLatestPatch({
260259
contractType: AP_POOL_QUOTA_KEEPER,
261-
version: version,
260+
minorVersion: version,
262261
constructorParams: abi.encode(pool),
263262
salt: bytes32(bytes20(marketConfigurator))
264263
});

contracts/factories/PriceOracleFactory.sol

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@ contract PriceOracleFactory is AbstractMarketFactory, IPriceOracleFactory {
5858
/// @notice Constructor
5959
/// @param addressProvider_ Address provider contract address
6060
constructor(address addressProvider_) AbstractFactory(addressProvider_) {
61-
priceFeedStore = _getContract(AP_PRICE_FEED_STORE, NO_VERSION_CONTROL);
61+
priceFeedStore = _getAddressOrRevert(AP_PRICE_FEED_STORE, NO_VERSION_CONTROL);
6262
}
6363

6464
// ---------- //
6565
// DEPLOYMENT //
6666
// ---------- //
6767

6868
function deployPriceOracle(address pool) external override onlyMarketConfigurators returns (DeployResult memory) {
69-
address priceOracle = _deploy({
69+
address priceOracle = _deployLatestPatch({
7070
contractType: AP_PRICE_ORACLE,
71-
version: version,
71+
minorVersion: version,
7272
constructorParams: abi.encode(_acl(pool)),
7373
salt: bytes32(bytes20(msg.sender))
7474
});
7575

7676
return DeployResult({
7777
newContract: priceOracle,
78-
onInstallOps: CallBuilder.build(_addToAccessList(msg.sender, priceOracle))
78+
onInstallOps: CallBuilder.build(_authorizeFactory(msg.sender, pool, priceOracle))
7979
});
8080
}
8181

@@ -94,14 +94,20 @@ contract PriceOracleFactory is AbstractMarketFactory, IPriceOracleFactory {
9494
return _setPriceFeed(priceOracle, underlying, underlyingPriceFeed, false);
9595
}
9696

97-
function onUpdatePriceOracle(address, address newPriceOracle, address oldPriceOracle)
97+
function onUpdatePriceOracle(address pool, address newPriceOracle, address oldPriceOracle)
9898
external
9999
view
100100
override(AbstractMarketFactory, IMarketFactory)
101101
returns (Call[] memory calls)
102102
{
103-
// QUESTION: maybe migrate pool's tokens instead?
104-
address[] memory tokens = IPriceOracleV3(oldPriceOracle).getTokens();
103+
calls = CallBuilder.build(_unauthorizeFactory(msg.sender, pool, oldPriceOracle));
104+
105+
address underlying = _underlying(pool);
106+
calls = calls.extend(
107+
_setPriceFeed(newPriceOracle, underlying, _getPriceFeed(oldPriceOracle, underlying, false), false)
108+
);
109+
110+
address[] memory tokens = _quotedTokens(_quotaKeeper(pool));
105111
uint256 numTokens = tokens.length;
106112
for (uint256 i; i < numTokens; ++i) {
107113
// FIXME: reallocating the whole array is not the most optimal solution

0 commit comments

Comments
 (0)