Skip to content

Commit 98558b1

Browse files
authored
feat: add risk admin role for configurator (#96)
* add risk admin role for configurator * support both risk and pool admin * updating configurator on goerli * deploy pool configurator
1 parent b7b36e1 commit 98558b1

10 files changed

+44
-29
lines changed

contracts/libraries/helpers/Errors.sol

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ library Errors {
2020
string public constant INVALID_FROM_BALANCE_AFTER_TRANSFER = "102";
2121
string public constant INVALID_TO_BALANCE_AFTER_TRANSFER = "103";
2222
string public constant CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST = "104";
23+
string public constant CALLER_NOT_RISK_ADMIN = "105";
24+
string public constant CALLER_NOT_RISK_OR_POOL_ADMIN = "106";
2325

2426
//math library erros
2527
string public constant MATH_MULTIPLICATION_OVERFLOW = "200";

contracts/protocol/LendPoolAddressesProvider.sol

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ contract LendPoolAddressesProvider is Ownable, ILendPoolAddressesProvider {
3434
bytes32 private constant BEND_DATA_PROVIDER = "BEND_DATA_PROVIDER";
3535
bytes32 private constant UI_DATA_PROVIDER = "UI_DATA_PROVIDER";
3636
bytes32 private constant WALLET_BALANCE_PROVIDER = "WALLET_BALANCE_PROVIDER";
37+
bytes32 public constant RISK_ADMIN = "RISK_ADMIN";
3738

3839
constructor(string memory marketId) {
3940
_setMarketId(marketId);

contracts/protocol/LendPoolConfigurator.sol

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ contract LendPoolConfigurator is Initializable, ILendPoolConfigurator {
3030
using NftConfiguration for DataTypes.NftConfigurationMap;
3131

3232
ILendPoolAddressesProvider internal _addressesProvider;
33+
bytes32 public constant RISK_ADMIN = "RISK_ADMIN";
3334

3435
modifier onlyPoolAdmin() {
3536
require(_addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN);
@@ -41,6 +42,14 @@ contract LendPoolConfigurator is Initializable, ILendPoolConfigurator {
4142
_;
4243
}
4344

45+
modifier onlyRiskOrPoolAdmin() {
46+
require(
47+
(_addressesProvider.getAddress(RISK_ADMIN) == msg.sender) || (_addressesProvider.getPoolAdmin() == msg.sender),
48+
Errors.CALLER_NOT_RISK_OR_POOL_ADMIN
49+
);
50+
_;
51+
}
52+
4453
function initialize(ILendPoolAddressesProvider provider) public initializer {
4554
_addressesProvider = provider;
4655
}
@@ -86,7 +95,7 @@ contract LendPoolConfigurator is Initializable, ILendPoolConfigurator {
8695
}
8796
}
8897

89-
function setBorrowingFlagOnReserve(address[] calldata assets, bool flag) external onlyPoolAdmin {
98+
function setBorrowingFlagOnReserve(address[] calldata assets, bool flag) external onlyRiskOrPoolAdmin {
9099
ILendPool cachedPool = _getLendPool();
91100
for (uint256 i = 0; i < assets.length; i++) {
92101
DataTypes.ReserveConfigurationMap memory currentConfig = cachedPool.getReserveConfiguration(assets[i]);
@@ -126,7 +135,7 @@ contract LendPoolConfigurator is Initializable, ILendPoolConfigurator {
126135
}
127136
}
128137

129-
function setFreezeFlagOnReserve(address[] calldata assets, bool flag) external onlyPoolAdmin {
138+
function setFreezeFlagOnReserve(address[] calldata assets, bool flag) external onlyRiskOrPoolAdmin {
130139
ILendPool cachedPool = _getLendPool();
131140
for (uint256 i = 0; i < assets.length; i++) {
132141
DataTypes.ReserveConfigurationMap memory currentConfig = cachedPool.getReserveConfiguration(assets[i]);
@@ -205,7 +214,7 @@ contract LendPoolConfigurator is Initializable, ILendPoolConfigurator {
205214
}
206215
}
207216

208-
function setFreezeFlagOnNft(address[] calldata assets, bool flag) external onlyPoolAdmin {
217+
function setFreezeFlagOnNft(address[] calldata assets, bool flag) external onlyRiskOrPoolAdmin {
209218
ILendPool cachedPool = _getLendPool();
210219
for (uint256 i = 0; i < assets.length; i++) {
211220
DataTypes.NftConfigurationMap memory currentConfig = cachedPool.getNftConfiguration(assets[i]);
@@ -322,7 +331,7 @@ contract LendPoolConfigurator is Initializable, ILendPoolConfigurator {
322331
address[] calldata assets,
323332
uint256 maxSupply,
324333
uint256 maxTokenId
325-
) external onlyPoolAdmin {
334+
) external onlyRiskOrPoolAdmin {
326335
ILendPool cachedPool = _getLendPool();
327336
for (uint256 i = 0; i < assets.length; i++) {
328337
cachedPool.setNftMaxSupplyAndTokenId(assets[i], maxSupply, maxTokenId);

deployments/deployed-contracts-goerli.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"deployer": "0xafF5C36642385b6c7Aaf7585eC785aB2316b5db6"
5454
},
5555
"ConfiguratorLogic": {
56-
"address": "0x1580A5E24B0c80c6DDd93225F1D11B62AEA0EC2d",
56+
"address": "0x935429b4eADc941d3af30F431844f86057242bDc",
5757
"deployer": "0xafF5C36642385b6c7Aaf7585eC785aB2316b5db6"
5858
},
5959
"LendPoolImpl": {
@@ -69,7 +69,7 @@
6969
"address": "0x7F64c32a3c13Bd245a7141a607A7E60DA585BA86"
7070
},
7171
"LendPoolConfiguratorImpl": {
72-
"address": "0x1e53E338C7f6Eb1F9c70E30C369ed41782635344"
72+
"address": "0x5F7Ae7Bb12712109500d9E4484170dE3A06eDd54"
7373
},
7474
"LendPoolConfigurator": {
7575
"address": "0x365661b853845F90b2b5B28a1A61bE5c54aE9FB2"

deployments/deployed-contracts-main.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"deployer": "0x868964fa49a6fd6e116FE82c8f4165904406f479"
6161
},
6262
"ConfiguratorLogic": {
63-
"address": "0xB90c4B3FAeFeC9FD325b968bB2f57e2696d03aeD",
63+
"address": "0xe4e70Fc5739A9E65654D26A25336e32182c69A26",
6464
"deployer": "0x868964fa49a6fd6e116FE82c8f4165904406f479"
6565
},
6666
"LendPoolImpl": {
@@ -76,7 +76,7 @@
7676
"address": "0x5f6ac80CdB9E87f3Cfa6a90E5140B9a16A361d5C"
7777
},
7878
"LendPoolConfiguratorImpl": {
79-
"address": "0xB72D8b46AADd08CCEafD52848201384b98849766"
79+
"address": "0xbD96056E10c2748D41F072649f4Dcc37874aB603"
8080
},
8181
"LendPoolConfigurator": {
8282
"address": "0x4f694372ced64B8Cf389A04f13E67ac0035A6449"

deployments/deployed-contracts-sepolia.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"deployer": "0xafF5C36642385b6c7Aaf7585eC785aB2316b5db6"
5757
},
5858
"ConfiguratorLogic": {
59-
"address": "0x0d00adF5988e21Ba7E75064292232f2bf0C689c2",
59+
"address": "0xdDD7c8B889fB0f599359f4dD90fE55e101EE67b9",
6060
"deployer": "0xafF5C36642385b6c7Aaf7585eC785aB2316b5db6"
6161
},
6262
"LendPoolImpl": {
@@ -72,7 +72,7 @@
7272
"address": "0xaA04774b15FC5555DabC2b87Bdd6976B6C9f4Bc0"
7373
},
7474
"LendPoolConfiguratorImpl": {
75-
"address": "0x77537048BEd42b0f3aCfd58D9e865774367FC0f5"
75+
"address": "0x8DC063164483a1548f62697bE9308081210Dd0D6"
7676
},
7777
"LendPoolConfigurator": {
7878
"address": "0x1252Ee9B28A632a653061bE91000f2Ccf40A9b26"

helpers/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export enum ProtocolErrors {
118118
INVALID_FROM_BALANCE_AFTER_TRANSFER = "102",
119119
INVALID_TO_BALANCE_AFTER_TRANSFER = "103",
120120
CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST = "104",
121+
CALLER_NOT_RISK_ADMIN = "105",
122+
CALLER_NOT_RISK_OR_POOL_ADMIN = "106",
121123

122124
//math library erros
123125
MATH_MULTIPLICATION_OVERFLOW = "200",

test/__setup.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
163163
const addressesProvider = await deployLendPoolAddressesProvider(BendConfig.MarketId);
164164
await waitForTx(await addressesProvider.setPoolAdmin(poolAdmin));
165165
await waitForTx(await addressesProvider.setEmergencyAdmin(emergencyAdmin));
166+
await waitForTx(await addressesProvider.setAddress(await addressesProvider.RISK_ADMIN(), poolAdmin));
166167

167168
await waitForTx(
168169
await addressesProviderRegistry.registerAddressesProvider(addressesProvider.address, BendConfig.ProviderId)

test/configurator-nft.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
5454
expect(isActive).to.be.equal(true);
5555
});
5656

57-
it("Check the onlyAdmin on deactivateRNft ", async () => {
57+
it("Check the onlyPoolAdmin on deactivateRNft ", async () => {
5858
const { configurator, users, bayc } = testEnv;
5959
await expect(
6060
configurator.connect(users[2].signer).setActiveFlagOnNft([bayc.address], false),
6161
CALLER_NOT_POOL_ADMIN
6262
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
6363
});
6464

65-
it("Check the onlyAdmin on activateNft ", async () => {
65+
it("Check the onlyPoolAdmin on activateNft ", async () => {
6666
const { configurator, users, bayc } = testEnv;
6767
await expect(
6868
configurator.connect(users[2].signer).setActiveFlagOnNft([bayc.address], true),
@@ -93,15 +93,15 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
9393
await expect(
9494
configurator.connect(users[2].signer).setFreezeFlagOnNft([bayc.address], true),
9595
CALLER_NOT_POOL_ADMIN
96-
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
96+
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_RISK_OR_POOL_ADMIN);
9797
});
9898

9999
it("Check the onlyAdmin on unfreezeNft ", async () => {
100100
const { configurator, users, bayc } = testEnv;
101101
await expect(
102102
configurator.connect(users[2].signer).setFreezeFlagOnNft([bayc.address], false),
103103
CALLER_NOT_POOL_ADMIN
104-
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
104+
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_RISK_OR_POOL_ADMIN);
105105
});
106106

107107
it("Deactivates the BAYC NFT as collateral", async () => {
@@ -126,7 +126,7 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
126126
expect(liquidationBonus).to.be.equal(500);
127127
});
128128

129-
it("Check the onlyAdmin on configureNftAsCollateral ", async () => {
129+
it("Check the onlyPoolAdmin on configureNftAsCollateral ", async () => {
130130
const { configurator, users, bayc } = testEnv;
131131
await expect(
132132
configurator.connect(users[2].signer).configureNftAsCollateral([bayc.address], "7500", "8000", "500"),
@@ -166,7 +166,7 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
166166
expect(minBidFine).to.be.equal(5000);
167167
});
168168

169-
it("Check the onlyAdmin on configureNftAsAuction ", async () => {
169+
it("Check the onlyPoolAdmin on configureNftAsAuction ", async () => {
170170
const { configurator, users, bayc } = testEnv;
171171
await expect(
172172
configurator.connect(users[2].signer).configureNftAsAuction([bayc.address], "1", "1", "100"),
@@ -216,7 +216,7 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
216216
expect(liquidationBonus).to.be.equal(500);
217217
});
218218

219-
it("Check the onlyAdmin on batchConfigNft ", async () => {
219+
it("Check the onlyPoolAdmin on batchConfigNft ", async () => {
220220
const { configurator, users, bayc } = testEnv;
221221
await expect(
222222
configurator.connect(users[2].signer).batchConfigNft(cfgInputParams),
@@ -303,7 +303,7 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
303303
);
304304
});
305305

306-
it("Check the onlyAdmin on setMaxNumberOfNfts ", async () => {
306+
it("Check the onlyPoolAdmin on setMaxNumberOfNfts ", async () => {
307307
const { configurator, users, pool } = testEnv;
308308
await expect(
309309
configurator.connect(users[2].signer).setMaxNumberOfNfts(512),
@@ -325,15 +325,15 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
325325
expect(wantVal2).to.be.equal(false);
326326
});
327327

328-
it("Check the onlyAdmin on approve interceptor ", async () => {
328+
it("Check the onlyPoolAdmin on approve interceptor ", async () => {
329329
const { configurator, users, pool } = testEnv;
330330
await expect(
331331
configurator.connect(users[2].signer).approveLoanRepaidInterceptor(pool.address, true),
332332
CALLER_NOT_POOL_ADMIN
333333
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
334334
});
335335

336-
it("Check the onlyAdmin on approve interceptor ", async () => {
336+
it("Check the onlyPoolAdmin on approve interceptor ", async () => {
337337
const { configurator, users, pool, bBAYC } = testEnv;
338338
await expect(
339339
configurator.connect(users[2].signer).purgeLoanRepaidInterceptor(bBAYC.address, [100], pool.address),
@@ -355,15 +355,15 @@ makeSuite("Configurator-NFT", (testEnv: TestEnv) => {
355355
expect(wantVal2).to.be.equal(false);
356356
});
357357

358-
it("Check the onlyAdmin on approve locker ", async () => {
358+
it("Check the onlyPoolAdmin on approve locker ", async () => {
359359
const { configurator, users, pool } = testEnv;
360360
await expect(
361361
configurator.connect(users[2].signer).approveFlashLoanLocker(pool.address, true),
362362
CALLER_NOT_POOL_ADMIN
363363
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
364364
});
365365

366-
it("Check the onlyAdmin on approve locker ", async () => {
366+
it("Check the onlyPoolAdmin on approve locker ", async () => {
367367
const { configurator, users, pool, bBAYC } = testEnv;
368368
await expect(
369369
configurator.connect(users[2].signer).purgeFlashLoanLocking(bBAYC.address, [100], pool.address),

test/configurator-reserve.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ makeSuite("Configurator-Reserve", (testEnv: TestEnv) => {
3939
expect(isActive).to.be.equal(true);
4040
});
4141

42-
it("Check the onlyAdmin on deactivateReserve ", async () => {
42+
it("Check the onlyPoolAdmin on deactivateReserve ", async () => {
4343
const { configurator, users, weth } = testEnv;
4444
await expect(
4545
configurator.connect(users[2].signer).setActiveFlagOnReserve([weth.address], false),
4646
CALLER_NOT_POOL_ADMIN
4747
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
4848
});
4949

50-
it("Check the onlyAdmin on activateReserve ", async () => {
50+
it("Check the onlyPoolAdmin on activateReserve ", async () => {
5151
const { configurator, users, weth } = testEnv;
5252
await expect(
5353
configurator.connect(users[2].signer).setActiveFlagOnReserve([weth.address], true),
@@ -88,15 +88,15 @@ makeSuite("Configurator-Reserve", (testEnv: TestEnv) => {
8888
await expect(
8989
configurator.connect(users[2].signer).setFreezeFlagOnReserve([weth.address], true),
9090
CALLER_NOT_POOL_ADMIN
91-
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
91+
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_RISK_OR_POOL_ADMIN);
9292
});
9393

9494
it("Check the onlyAdmin on unfreezeReserve ", async () => {
9595
const { configurator, users, weth } = testEnv;
9696
await expect(
9797
configurator.connect(users[2].signer).setFreezeFlagOnReserve([weth.address], false),
9898
CALLER_NOT_POOL_ADMIN
99-
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
99+
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_RISK_OR_POOL_ADMIN);
100100
});
101101

102102
it("Deactivates the ETH reserve for borrowing", async () => {
@@ -134,15 +134,15 @@ makeSuite("Configurator-Reserve", (testEnv: TestEnv) => {
134134
await expect(
135135
configurator.connect(users[2].signer).setBorrowingFlagOnReserve([weth.address], false),
136136
CALLER_NOT_POOL_ADMIN
137-
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
137+
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_RISK_OR_POOL_ADMIN);
138138
});
139139

140140
it("Check the onlyAdmin on enableBorrowingOnReserve ", async () => {
141141
const { configurator, users, weth } = testEnv;
142142
await expect(
143143
configurator.connect(users[2].signer).setBorrowingFlagOnReserve([weth.address], true),
144144
CALLER_NOT_POOL_ADMIN
145-
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
145+
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_RISK_OR_POOL_ADMIN);
146146
});
147147

148148
it("Changes the reserve factor of WETH", async () => {
@@ -239,7 +239,7 @@ makeSuite("Configurator-Reserve", (testEnv: TestEnv) => {
239239
);
240240
});
241241

242-
it("Check the onlyAdmin on setMaxNumberOfReserves ", async () => {
242+
it("Check the onlyPoolAdmin on setMaxNumberOfReserves ", async () => {
243243
const { configurator, users, pool } = testEnv;
244244
await expect(
245245
configurator.connect(users[2].signer).setMaxNumberOfReserves(512),

0 commit comments

Comments
 (0)