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

Merge changes from private-contracts repo into develop #950

Closed EdNoepel closed 1 year ago

EdNoepel commented 1 year ago

Description of change

High level

Merge changes from private-contracts repository designed to mitigate griefing vector found through bug bounty program, and address issues with liquidations game-theory.

Description of bug or vulnerability and solution

Contract size

~2% reduction in pool contract size.

Pre Change

============ Deployment Bytecode Sizes ============
  ERC721Pool               -  24,478B  (99.60%)
  ERC20Pool                -  23,761B  (96.68%)
  PositionManager          -  18,787B  (76.44%)
  PositionNFTSVG           -  15,257B  (62.08%)
  TakerActions             -  15,146B  (61.63%)
  PoolInfoUtils            -  13,622B  (55.43%)

Post Change

============ Deployment Bytecode Sizes ============
  ERC721Pool               -  24,010B  (97.69%)
  ERC20Pool                -  23,341B  (94.97%)
  PositionManager          -  18,787B  (76.44%)
  TakerActions             -  15,866B  (64.56%)
  PositionNFTSVG           -  15,257B  (62.08%)
  PoolInfoUtils            -  13,288B  (54.07%)

Gas usage

Pre Change

src/ERC20Pool.sol:ERC20Pool contract
Function Name min avg median max # calls
addCollateral 1553 162305 144032 400771 34
addQuoteToken 1950 253028 170017 723088 935
bucketCollateralDust 1152 1948 1152 3099 17
bucketExchangeRate 14696 17221 16006 33332 889
bucketInfo 4571 7308 6173 36833 3134
bucketTake 8184 123958 127809 423264 33
drawDebt 7540 248578 252878 617766 555
kick 6950 553939 619213 773745 56
kickReserveAuction 3974 57147 57400 129779 110
kickerInfo 1304 2390 1304 5304 151
moveQuoteToken 1918 142033 107079 634633 41
removeCollateral 4412 54932 56406 157370 73
removeQuoteToken 4698 69308 62490 621261 431
repayDebt 10042 165664 107530 590635 322
settle 11765 197788 182134 509375 27
take 9175 175718 194245 591333 47
takeReserves 25814 104374 122736 134064 59
src/ERC721Pool.sol:ERC721Pool contract
Function Name min avg median max # calls
addCollateral 23601 314258 303067 970887 9
addQuoteToken 43467 281480 193195 682194 199
bucketInfo 4148 10145 7478 39239 155901
bucketTake 78794 221603 176716 531020 14
bucketTokenIds 1279 1279 1279 1279 38
drawDebt 10720 841261 325808 91976916 175
kick 6950 556558 611749 835049 13
kickReserveAuction 6796 71688 80572 131622 8
kickerInfo 1326 2742 1326 5326 48
moveQuoteToken 45953 53109 46131 67228 6
removeCollateral 3779 65628 63033 167878 18
removeQuoteToken 4830 62275 58923 182722 150
repayDebt 8555 600472 113034 59207740 133
settle 109200 323254 255788 715264 11
take 12160 317870 385349 728012 13
takeReserves 4449 74464 63969 142883 8

Post Change

src/ERC20Pool.sol:ERC20Pool contract
Function Name min avg median max # calls
addCollateral 1553 162272 143653 400771 34
addQuoteToken 1950 255301 172461 723088 921
bucketCollateralDust 1152 1947 1152 3099 17
bucketExchangeRate 14696 17235 16006 33332 886
bucketInfo 4571 7228 6206 36833 3413
bucketTake 8165 112991 107028 397012 34
drawDebt 7442 242913 229782 592550 502
kick 6878 474303 572805 713526 55
kickReserveAuction 4090 47808 51755 100698 107
kickerInfo 1304 2332 1304 5304 140
moveQuoteToken 1918 141583 107168 634633 41
removeCollateral 4412 57077 57314 157370 103
removeQuoteToken 4698 70236 63583 621261 407
repayDebt 9850 192239 121285 589836 296
settle 11765 205911 171570 509375 59
take 9156 184757 184703 569729 42
takeReserves 6714 113142 140256 153184 61
src/ERC721Pool.sol:ERC721Pool contract
Function Name min avg median max # calls
addCollateral 23601 406461 303067 1800710 9
addQuoteToken 43467 279826 215624 682428 185
bucketInfo 4148 9476 7181 39239 111542
bucketTake 98327 193479 136773 508779 13
bucketTokenIds 1279 1279 1279 1279 44
drawDebt 12207 847730 302620 91958312 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 79748 66745 245092 21
removeQuoteToken 4830 62755 59002 182722 142
repayDebt 8351 682049 117364 59207802 118
settle 108920 332643 268003 714682 15
take 12141 311598 382011 706248 13
takeReserves 4449 82426 63969 164783 8