@@ -15,9 +15,9 @@ import {IrmMock as Irm} from "src/mocks/IrmMock.sol";
15
15
contract BlueTest is Test {
16
16
using MathLib for uint ;
17
17
18
- address private constant borrower = address (1234 );
19
- address private constant liquidator = address (5678 );
20
- uint private constant lltv = 0.8 ether ;
18
+ address private constant BORROWER = address (1234 );
19
+ address private constant LIQUIDATOR = address (5678 );
20
+ uint private constant LLTV = 0.8 ether ;
21
21
address private constant OWNER = address (0xdead );
22
22
23
23
Blue private blue;
@@ -46,13 +46,13 @@ contract BlueTest is Test {
46
46
borrowableOracle,
47
47
collateralOracle,
48
48
irm,
49
- lltv
49
+ LLTV
50
50
);
51
51
id = Id.wrap (keccak256 (abi.encode (market)));
52
52
53
53
vm.startPrank (OWNER);
54
54
blue.enableIrm (irm);
55
- blue.enableLltv (lltv );
55
+ blue.enableLltv (LLTV );
56
56
blue.createMarket (market);
57
57
vm.stopPrank ();
58
58
@@ -63,11 +63,11 @@ contract BlueTest is Test {
63
63
64
64
borrowableAsset.approve (address (blue), type (uint ).max);
65
65
collateralAsset.approve (address (blue), type (uint ).max);
66
- vm.startPrank (borrower );
66
+ vm.startPrank (BORROWER );
67
67
borrowableAsset.approve (address (blue), type (uint ).max);
68
68
collateralAsset.approve (address (blue), type (uint ).max);
69
69
vm.stopPrank ();
70
- vm.startPrank (liquidator );
70
+ vm.startPrank (LIQUIDATOR );
71
71
borrowableAsset.approve (address (blue), type (uint ).max);
72
72
collateralAsset.approve (address (blue), type (uint ).max);
73
73
vm.stopPrank ();
@@ -104,7 +104,7 @@ contract BlueTest is Test {
104
104
}
105
105
106
106
function invariantLltvEnabled () public {
107
- assertTrue (blue.isLltvEnabled (lltv ));
107
+ assertTrue (blue.isLltvEnabled (LLTV ));
108
108
}
109
109
110
110
// Tests
@@ -149,7 +149,7 @@ contract BlueTest is Test {
149
149
}
150
150
151
151
function testCreateMarketWithEnabledIrm (Market memory marketFuzz ) public {
152
- marketFuzz.lltv = lltv ;
152
+ marketFuzz.lltv = LLTV ;
153
153
154
154
vm.startPrank (OWNER);
155
155
blue.enableIrm (marketFuzz.irm);
@@ -191,7 +191,7 @@ contract BlueTest is Test {
191
191
}
192
192
193
193
function testCreateMarketWithNotEnabledLltv (Market memory marketFuzz ) public {
194
- vm.assume (marketFuzz.lltv != lltv );
194
+ vm.assume (marketFuzz.lltv != LLTV );
195
195
marketFuzz.irm = irm;
196
196
197
197
vm.prank (OWNER);
@@ -223,17 +223,17 @@ contract BlueTest is Test {
223
223
}
224
224
225
225
if (amountBorrowed > amountLent) {
226
- vm.prank (borrower );
226
+ vm.prank (BORROWER );
227
227
vm.expectRevert ("not enough liquidity " );
228
228
blue.borrow (market, amountBorrowed);
229
229
return ;
230
230
}
231
231
232
- vm.prank (borrower );
232
+ vm.prank (BORROWER );
233
233
blue.borrow (market, amountBorrowed);
234
234
235
- assertEq (blue.borrowShare (id, borrower ), 1e18 , "borrow share " );
236
- assertEq (borrowableAsset.balanceOf (borrower ), amountBorrowed, "borrower balance " );
235
+ assertEq (blue.borrowShare (id, BORROWER ), 1e18 , "borrow share " );
236
+ assertEq (borrowableAsset.balanceOf (BORROWER ), amountBorrowed, "BORROWER balance " );
237
237
assertEq (borrowableAsset.balanceOf (address (blue)), amountLent - amountBorrowed, "blue balance " );
238
238
}
239
239
@@ -246,7 +246,7 @@ contract BlueTest is Test {
246
246
borrowableAsset.setBalance (address (this ), amountLent);
247
247
blue.supply (market, amountLent);
248
248
249
- vm.prank (borrower );
249
+ vm.prank (BORROWER );
250
250
blue.borrow (market, amountBorrowed);
251
251
252
252
if (amountWithdrawn > amountLent - amountBorrowed) {
@@ -285,20 +285,20 @@ contract BlueTest is Test {
285
285
collateralOracle.setPrice (priceCollateral);
286
286
287
287
borrowableAsset.setBalance (address (this ), amountBorrowed);
288
- collateralAsset.setBalance (borrower , amountCollateral);
288
+ collateralAsset.setBalance (BORROWER , amountCollateral);
289
289
290
290
blue.supply (market, amountBorrowed);
291
291
292
- vm.prank (borrower );
292
+ vm.prank (BORROWER );
293
293
blue.supplyCollateral (market, amountCollateral);
294
294
295
295
uint collateralValue = amountCollateral.wMul (priceCollateral);
296
296
uint borrowValue = amountBorrowed.wMul (priceBorrowable);
297
- if (borrowValue == 0 || (collateralValue > 0 && borrowValue <= collateralValue.wMul (lltv ))) {
298
- vm.prank (borrower );
297
+ if (borrowValue == 0 || (collateralValue > 0 && borrowValue <= collateralValue.wMul (LLTV ))) {
298
+ vm.prank (BORROWER );
299
299
blue.borrow (market, amountBorrowed);
300
300
} else {
301
- vm.prank (borrower );
301
+ vm.prank (BORROWER );
302
302
vm.expectRevert ("not enough collateral " );
303
303
blue.borrow (market, amountBorrowed);
304
304
}
@@ -312,15 +312,15 @@ contract BlueTest is Test {
312
312
borrowableAsset.setBalance (address (this ), amountLent);
313
313
blue.supply (market, amountLent);
314
314
315
- vm.startPrank (borrower );
315
+ vm.startPrank (BORROWER );
316
316
blue.borrow (market, amountBorrowed);
317
317
blue.repay (market, amountRepaid);
318
318
vm.stopPrank ();
319
319
320
320
assertApproxEqAbs (
321
- blue.borrowShare (id, borrower ), (amountBorrowed - amountRepaid) * 1e18 / amountBorrowed, 1e3 , "borrow share "
321
+ blue.borrowShare (id, BORROWER ), (amountBorrowed - amountRepaid) * 1e18 / amountBorrowed, 1e3 , "borrow share "
322
322
);
323
- assertEq (borrowableAsset.balanceOf (borrower ), amountBorrowed - amountRepaid, "borrower balance " );
323
+ assertEq (borrowableAsset.balanceOf (BORROWER ), amountBorrowed - amountRepaid, "BORROWER balance " );
324
324
assertEq (borrowableAsset.balanceOf (address (blue)), amountLent - amountBorrowed + amountRepaid, "blue balance " );
325
325
}
326
326
@@ -360,83 +360,83 @@ contract BlueTest is Test {
360
360
amountLent = bound (amountLent, 1000 , 2 ** 64 );
361
361
362
362
uint amountCollateral = amountLent;
363
- uint borrowingPower = amountCollateral.wMul (lltv );
363
+ uint borrowingPower = amountCollateral.wMul (LLTV );
364
364
uint amountBorrowed = borrowingPower.wMul (0.8e18 );
365
- uint toSeize = amountCollateral.wMul (lltv );
366
- uint incentive = WAD + ALPHA.wMul (WAD.wDiv (lltv ) - WAD);
365
+ uint toSeize = amountCollateral.wMul (LLTV );
366
+ uint incentive = WAD + ALPHA.wMul (WAD.wDiv (LLTV ) - WAD);
367
367
368
368
borrowableAsset.setBalance (address (this ), amountLent);
369
- collateralAsset.setBalance (borrower , amountCollateral);
370
- borrowableAsset.setBalance (liquidator , amountBorrowed);
369
+ collateralAsset.setBalance (BORROWER , amountCollateral);
370
+ borrowableAsset.setBalance (LIQUIDATOR , amountBorrowed);
371
371
372
372
// Supply
373
373
blue.supply (market, amountLent);
374
374
375
375
// Borrow
376
- vm.startPrank (borrower );
376
+ vm.startPrank (BORROWER );
377
377
blue.supplyCollateral (market, amountCollateral);
378
378
blue.borrow (market, amountBorrowed);
379
379
vm.stopPrank ();
380
380
381
381
// Price change
382
382
borrowableOracle.setPrice (2e18 );
383
383
384
- uint liquidatorNetWorthBefore = netWorth (liquidator );
384
+ uint liquidatorNetWorthBefore = netWorth (LIQUIDATOR );
385
385
386
386
// Liquidate
387
- vm.prank (liquidator );
388
- blue.liquidate (market, borrower , toSeize);
387
+ vm.prank (LIQUIDATOR );
388
+ blue.liquidate (market, BORROWER , toSeize);
389
389
390
- uint liquidatorNetWorthAfter = netWorth (liquidator );
390
+ uint liquidatorNetWorthAfter = netWorth (LIQUIDATOR );
391
391
392
392
uint expectedRepaid = toSeize.wMul (collateralOracle.price ()).wDiv (incentive).wDiv (borrowableOracle.price ());
393
393
uint expectedNetWorthAfter = liquidatorNetWorthBefore + toSeize.wMul (collateralOracle.price ())
394
394
- expectedRepaid.wMul (borrowableOracle.price ());
395
- assertEq (liquidatorNetWorthAfter, expectedNetWorthAfter, "liquidator net worth " );
396
- assertApproxEqAbs (borrowBalance (borrower ), amountBorrowed - expectedRepaid, 100 , "borrower balance " );
397
- assertEq (blue.collateral (id, borrower ), amountCollateral - toSeize, "borrower collateral " );
395
+ assertEq (liquidatorNetWorthAfter, expectedNetWorthAfter, "LIQUIDATOR net worth " );
396
+ assertApproxEqAbs (borrowBalance (BORROWER ), amountBorrowed - expectedRepaid, 100 , "BORROWER balance " );
397
+ assertEq (blue.collateral (id, BORROWER ), amountCollateral - toSeize, "BORROWER collateral " );
398
398
}
399
399
400
400
function testRealizeBadDebt (uint amountLent ) public {
401
401
borrowableOracle.setPrice (1e18 );
402
402
amountLent = bound (amountLent, 1000 , 2 ** 64 );
403
403
404
404
uint amountCollateral = amountLent;
405
- uint borrowingPower = amountCollateral.wMul (lltv );
405
+ uint borrowingPower = amountCollateral.wMul (LLTV );
406
406
uint amountBorrowed = borrowingPower.wMul (0.8e18 );
407
407
uint toSeize = amountCollateral;
408
408
uint incentive = WAD + ALPHA.wMul (WAD.wDiv (market.lltv) - WAD);
409
409
410
410
borrowableAsset.setBalance (address (this ), amountLent);
411
- collateralAsset.setBalance (borrower , amountCollateral);
412
- borrowableAsset.setBalance (liquidator , amountBorrowed);
411
+ collateralAsset.setBalance (BORROWER , amountCollateral);
412
+ borrowableAsset.setBalance (LIQUIDATOR , amountBorrowed);
413
413
414
414
// Supply
415
415
blue.supply (market, amountLent);
416
416
417
417
// Borrow
418
- vm.startPrank (borrower );
418
+ vm.startPrank (BORROWER );
419
419
blue.supplyCollateral (market, amountCollateral);
420
420
blue.borrow (market, amountBorrowed);
421
421
vm.stopPrank ();
422
422
423
423
// Price change
424
424
borrowableOracle.setPrice (100e18 );
425
425
426
- uint liquidatorNetWorthBefore = netWorth (liquidator );
426
+ uint liquidatorNetWorthBefore = netWorth (LIQUIDATOR );
427
427
428
428
// Liquidate
429
- vm.prank (liquidator );
430
- blue.liquidate (market, borrower , toSeize);
429
+ vm.prank (LIQUIDATOR );
430
+ blue.liquidate (market, BORROWER , toSeize);
431
431
432
- uint liquidatorNetWorthAfter = netWorth (liquidator );
432
+ uint liquidatorNetWorthAfter = netWorth (LIQUIDATOR );
433
433
434
434
uint expectedRepaid = toSeize.wMul (collateralOracle.price ()).wDiv (incentive).wDiv (borrowableOracle.price ());
435
435
uint expectedNetWorthAfter = liquidatorNetWorthBefore + toSeize.wMul (collateralOracle.price ())
436
436
- expectedRepaid.wMul (borrowableOracle.price ());
437
- assertEq (liquidatorNetWorthAfter, expectedNetWorthAfter, "liquidator net worth " );
438
- assertEq (borrowBalance (borrower ), 0 , "borrower balance " );
439
- assertEq (blue.collateral (id, borrower ), 0 , "borrower collateral " );
437
+ assertEq (liquidatorNetWorthAfter, expectedNetWorthAfter, "LIQUIDATOR net worth " );
438
+ assertEq (borrowBalance (BORROWER ), 0 , "BORROWER balance " );
439
+ assertEq (blue.collateral (id, BORROWER ), 0 , "BORROWER collateral " );
440
440
uint expectedBadDebt = amountBorrowed - expectedRepaid;
441
441
assertGt (expectedBadDebt, 0 , "bad debt " );
442
442
assertApproxEqAbs (supplyBalance (address (this )), amountLent - expectedBadDebt, 10 , "lender supply balance " );
@@ -449,14 +449,14 @@ contract BlueTest is Test {
449
449
borrowableAsset.setBalance (address (this ), firstAmount);
450
450
blue.supply (market, firstAmount);
451
451
452
- borrowableAsset.setBalance (borrower , secondAmount);
453
- vm.prank (borrower );
452
+ borrowableAsset.setBalance (BORROWER , secondAmount);
453
+ vm.prank (BORROWER );
454
454
blue.supply (market, secondAmount);
455
455
456
456
assertApproxEqAbs (supplyBalance (address (this )), firstAmount, 100 , "same balance first user " );
457
457
assertEq (blue.supplyShare (id, address (this )), 1e18 , "expected shares first user " );
458
- assertApproxEqAbs (supplyBalance (borrower ), secondAmount, 100 , "same balance second user " );
459
- assertEq (blue.supplyShare (id, borrower ), secondAmount * 1e18 / firstAmount, "expected shares second user " );
458
+ assertApproxEqAbs (supplyBalance (BORROWER ), secondAmount, 100 , "same balance second user " );
459
+ assertEq (blue.supplyShare (id, BORROWER ), secondAmount * 1e18 / firstAmount, "expected shares second user " );
460
460
}
461
461
462
462
function testUnknownMarket (Market memory marketFuzz ) public {
0 commit comments