Skip to content

Commit 29f6a84

Browse files
authored
Add a constraint for the amount of pools to TCA (trusttoken#993)
* Introduce maxPools * Add maxPools setter * Add event emission on changing max pools * Restrict the amount of pools supported by TCA * Rename test
1 parent 365ddda commit 29f6a84

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

contracts/truefi2/TrueCreditAgency.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ contract TrueCreditAgency is UpgradeableClaimable, ITrueCreditAgency {
117117
/// @dev minimum credit score required to use lines of credit
118118
uint256 public minCreditScore;
119119

120+
// maximum amount of pools credit agency can handle at once
121+
uint256 public maxPools;
122+
120123
// ======= STORAGE DECLARATION END ============
121124

122125
/// @dev emit `newRateAdjuster` when rate adjuster changed
@@ -140,11 +143,15 @@ contract TrueCreditAgency is UpgradeableClaimable, ITrueCreditAgency {
140143
/// @dev emit `newValue` when minimum credit score is changed
141144
event MinCreditScoreChanged(uint256 newValue);
142145

146+
/// @dev emit `maxPools` when maximum pools amount is changed
147+
event MaxPoolsChanged(uint256 maxPools);
148+
143149
/// @dev initialize
144150
function initialize(ITrueFiCreditOracle _creditOracle, ITrueRateAdjuster _rateAdjuster) public initializer {
145151
UpgradeableClaimable.initialize(msg.sender);
146152
creditOracle = _creditOracle;
147153
rateAdjuster = _rateAdjuster;
154+
maxPools = 10;
148155
interestRepaymentPeriod = 31 days;
149156
}
150157

@@ -173,6 +180,12 @@ contract TrueCreditAgency is UpgradeableClaimable, ITrueCreditAgency {
173180
emit MinCreditScoreChanged(newValue);
174181
}
175182

183+
/// @dev set maxPools to `_maxPools`
184+
function setMaxPools(uint256 _maxPools) external onlyOwner {
185+
maxPools = _maxPools;
186+
emit MaxPoolsChanged(_maxPools);
187+
}
188+
176189
/// @dev set borrower `who` to whitelist status `isAllowed`
177190
function allowBorrower(address who, bool isAllowed) external onlyOwner {
178191
isBorrowerAllowed[who] = isAllowed;
@@ -184,6 +197,7 @@ contract TrueCreditAgency is UpgradeableClaimable, ITrueCreditAgency {
184197
* Loop through
185198
*/
186199
function allowPool(ITrueFiPool2 pool, bool isAllowed) external onlyOwner {
200+
require(pools.length < maxPools, "TrueRatingAgency: Pools number has reached the limit");
187201
// if allowing new pool, push to pools array
188202
if (!isPoolAllowed[pool] && isAllowed) {
189203
pools.push(pool);

test/truefi2/lines-of-credit/TrueCreditAgency.test.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('TrueCreditAgency', () => {
6767
timeTravel = (time: number) => _timeTravel(_provider, time)
6868
provider = _provider
6969

70-
;({
70+
; ({
7171
standardToken: tusd,
7272
standardPool: tusdPool,
7373
feeToken: usdc,
@@ -101,9 +101,17 @@ describe('TrueCreditAgency', () => {
101101
expect(await creditAgency.creditOracle()).to.equal(creditOracle.address)
102102
})
103103

104+
it('sets rateAdjuster', async () => {
105+
expect(await creditAgency.rateAdjuster()).to.equal(rateAdjuster.address)
106+
})
107+
104108
it('sets interestRepaymentPeriod', async () => {
105109
expect(await creditAgency.interestRepaymentPeriod()).to.equal(MONTH)
106110
})
111+
112+
it('sets maxPools to 10', async () => {
113+
expect(await creditAgency.maxPools()).to.equal(10)
114+
})
107115
})
108116

109117
describe('Ownership', () => {
@@ -157,6 +165,24 @@ describe('TrueCreditAgency', () => {
157165
})
158166
})
159167

168+
describe('setMaxPools', () => {
169+
it('reverts if not called by the owner', async () => {
170+
await expect(creditAgency.connect(borrower).setMaxPools(1))
171+
.to.be.revertedWith('Ownable: caller is not the owner')
172+
})
173+
174+
it('changes maximum pools capacity', async () => {
175+
await creditAgency.setMaxPools(1)
176+
expect(await creditAgency.maxPools()).to.eq(1)
177+
})
178+
179+
it('emits event', async () => {
180+
await expect(creditAgency.setMaxPools(1))
181+
.to.emit(creditAgency, 'MaxPoolsChanged')
182+
.withArgs(1)
183+
})
184+
})
185+
160186
describe('Borrower allowance', () => {
161187
it('only owner can set allowance', async () => {
162188
await expect(creditAgency.connect(borrower).allowBorrower(borrower.address, true))
@@ -185,7 +211,14 @@ describe('TrueCreditAgency', () => {
185211
}
186212
}
187213
it('can only be called by the owner', async () => {
188-
await expect(creditAgency.connect(borrower).allowPool(tusdPool.address, true)).to.be.revertedWith('Ownable: caller is not the owner')
214+
await expect(creditAgency.connect(borrower).allowPool(tusdPool.address, true))
215+
.to.be.revertedWith('Ownable: caller is not the owner')
216+
})
217+
218+
it('reverts if there are too many pools', async () => {
219+
await creditAgency.setMaxPools(1)
220+
await expect(creditAgency.allowPool(usdcPool.address, true))
221+
.to.be.revertedWith('TrueRatingAgency: Pools number has reached the limit')
189222
})
190223

191224
it('changes pool allowance status', async () => {

0 commit comments

Comments
 (0)