ajna-finance / ajna-core

The Ajna protocol is a non-custodial, peer-to-peer, permissionless lending, borrowing and trading system that requires no governance or external price feeds to function.
https://www.ajna.finance/
Other
31 stars 11 forks source link

Reuse _isCollateralized method in repayment #959

Closed EdNoepel closed 1 year ago

EdNoepel commented 1 year ago

Description of change

High level

Reuse _isCollateralized method in repayment. Reusing this code will allow us to more easily change the collateralization requirement / threshold price. Expanded unit tests for PoolHelper._isCollateralized and PoolInfoUtils._collateralization methods.

Description of bug or vulnerability and solution

No bug/vulnerability.

Contract size

Contract sizes practically unaffected.

Pre Change

============ Deployment Bytecode Sizes ============
  ERC721Pool               -  24,069B  (97.93%)
  ERC20Pool                -  23,360B  (95.05%)
  PoolInfoUtils            -  13,288B  (54.07%)
  BorrowerActions          -   9,358B  (38.08%)

Post Change

============ Deployment Bytecode Sizes ============
  ERC721Pool               -  24,069B  (97.93%)
  ERC20Pool                -  23,360B  (95.05%)
  PoolInfoUtils            -  13,258B  (53.94%)
  BorrowerActions          -   9,346B  (38.03%)

Gas usage

There was a slight increase in cost to repayDebt.

Pre Change

src/ERC20Pool.sol:ERC20Pool contract
Function Name min avg median max # calls
addCollateral 1553 162421 144126 400771 34
addQuoteToken 1950 256226 171180 723088 919
bucketCollateralDust 1152 1834 1152 3099 17
bucketExchangeRate 14696 17243 16006 33332 865
bucketInfo 4571 7238 6206 42027 3283
bucketTake 8165 111835 107046 357768 34
drawDebt 7442 243934 229841 592550 504
kick 6878 477983 572805 713526 55
kickReserveAuction 4090 48187 51755 100698 105
kickerInfo 1304 2332 1304 5304 140
moveQuoteToken 1918 151323 107324 634633 41
removeCollateral 4412 57217 58408 157370 100
removeQuoteToken 4698 70245 63688 621261 405
repayDebt 9853 191633 120664 589911 296
settle 11765 202099 170123 510561 58
take 9159 185511 184787 570795 42
takeReserves 6714 113862 140256 153184 60
src/ERC721Pool.sol:ERC721Pool contract
Function Name min avg median max # calls
addCollateral 23601 894551 303067 6193522 9
addQuoteToken 43467 280023 215624 682428 183
bucketInfo 4148 9476 7181 39239 111522
bucketTake 98327 193479 136773 508779 13
bucketTokenIds 1279 1279 1279 1279 120
drawDebt 12207 694581 302620 66535639 166
kick 6878 517649 565965 783665 13
kickReserveAuction 6912 57451 64977 104077 8
kickerInfo 1326 2468 1326 5326 42
moveQuoteToken 45953 53109 46131 67228 6
removeCollateral 3779 112208 66745 926760 21
removeQuoteToken 4830 62850 59734 182722 140
repayDebt 8354 543587 117424 42863028 118
settle 108920 332643 268003 714682 15
take 12144 311693 382145 706382 13
takeReserves 4449 82426 63969 164783 8

Post Change

src/ERC20Pool.sol:ERC20Pool contract
Function Name min avg median max # calls
addCollateral 1553 162405 144126 400771 34
addQuoteToken 1950 253806 170017 723088 942
bucketCollateralDust 1152 1948 1152 3099 17
bucketExchangeRate 14696 17207 16006 33332 928
bucketInfo 4571 7172 6206 46561 3980
bucketTake 8165 113178 108059 398012 34
drawDebt 7442 244350 230546 592550 515
kick 6878 483024 572805 713526 54
kickReserveAuction 4090 44417 51755 100698 129
kickerInfo 1304 2332 1304 5304 140
moveQuoteToken 1918 148419 107324 634633 41
removeCollateral 4412 56894 58408 157370 103
removeQuoteToken 4698 70373 63688 621261 403
repayDebt 9853 193967 126946 589911 307
settle 11765 206109 176798 451449 58
take 9159 184352 184787 570795 42
takeReserves 6714 106542 135626 153184 72
src/ERC721Pool.sol:ERC721Pool contract
Function Name min avg median max # calls
addCollateral 23601 571551 303067 3286525 9
addQuoteToken 43467 280023 215624 682428 183
bucketInfo 4148 9476 7181 39239 111522
bucketTake 98327 193479 136773 508779 13
bucketTokenIds 1279 1279 1279 1279 65
drawDebt 12207 300847 302620 1175788 166
kick 6878 517649 565965 783665 13
kickReserveAuction 6912 57451 64977 104077 8
kickerInfo 1326 2468 1326 5326 42
moveQuoteToken 45953 53109 46131 67228 6
removeCollateral 3779 88802 66745 435224 21
removeQuoteToken 4830 62850 59734 182722 140
repayDebt 8354 187537 117597 835920 118
settle 108920 332643 268003 714682 15
take 12144 311693 382145 706382 13
takeReserves 4449 82426 63969 164783 8