Skip to content

Commit a5e00c2

Browse files
authored
Merge pull request #762 from ajna-finance/develop
Merge develop in master
2 parents 65bcd8e + c3ec05a commit a5e00c2

File tree

222 files changed

+18575
-8643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+18575
-8643
lines changed

.env.example

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ SOLC_VERSION=0.8.14
2525
AJNA_TOKEN=0xaadebCF61AA7Da0573b524DE57c67aDa797D46c5
2626

2727
# path to the JSON keystore file for your deployment account
28-
DEPLOY_KEY=
28+
DEPLOY_KEY=
29+
30+
# Default token precisions for (invariant) testing
31+
QUOTE_PRECISION = 18
32+
COLLATERAL_PRECISION = 18
33+
34+
# Default bucket Index for (invariant) testing
35+
BUCKET_INDEX_ERC20 = 2570
36+
BUCKET_INDEX_ERC721 = 850
37+
38+
# Default no of buckets to use for (invariant) testing
39+
NO_OF_BUCKETS = 3

.github/workflows/forge-test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ env:
88

99
jobs:
1010
check:
11+
env:
12+
QUOTE_PRECISION: 18
13+
COLLATERAL_PRECISION: 18
14+
BUCKET_INDEX_ERC20: 2570
15+
BUCKET_INDEX_ERC721: 850
16+
NO_OF_BUCKETS: 3
1117
strategy:
1218
fail-fast: true
1319

@@ -31,5 +37,5 @@ jobs:
3137

3238
- name: Run tests
3339
run: |
34-
make test-with-gas-report
40+
make test-with-gas-report && make test-regression
3541
id: test

Makefile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
# (-include to ignore error if it does not exist)
33
-include .env
44

5+
# Default token precisions for invariant testing
6+
QUOTE_PRECISION = 18
7+
COLLATERAL_PRECISION = 18
8+
9+
# Default buckets for invariant testing
10+
BUCKET_INDEX_ERC20 = 2570
11+
BUCKET_INDEX_ERC721 = 850
12+
NO_OF_BUCKETS = 3
13+
514
all: clean install build
615

716
# Clean the repo
@@ -14,11 +23,19 @@ install :; git submodule update --init --recursive
1423
build :; forge clean && forge build
1524

1625
# Tests
17-
test :; forge test --no-match-test "testLoad|invariant" # --ffi # enable if you need the `ffi` cheat code on HEVM
18-
test-with-gas-report :; FOUNDRY_PROFILE=optimized forge test --no-match-test "testLoad|invariant" --gas-report # --ffi # enable if you need the `ffi` cheat code on HEVM
19-
test-load :; FOUNDRY_PROFILE=optimized forge test --match-test testLoad --gas-report
20-
test-invariant :; forge t --mt invariant
21-
coverage :; forge coverage --no-match-test "testLoad|invariant"
26+
test :; forge test --no-match-test "testLoad|invariant|test_regression" # --ffi # enable if you need the `ffi` cheat code on HEVM
27+
test-with-gas-report :; forge test --no-match-test "testLoad|invariant|test_regression" --gas-report # --ffi # enable if you need the `ffi` cheat code on HEVM
28+
test-load :; forge test --match-test testLoad --gas-report
29+
test-invariant :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest
30+
test-invariant-erc20 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest --mc ERC20
31+
test-invariant-erc721 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest --mc ERC721
32+
test-regression :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression
33+
test-regression-erc20 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression --mc ERC20
34+
test-regression-erc721 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression --mc ERC721
35+
coverage :; forge coverage --no-match-test "testLoad|invariant"
36+
test-invariant-erc20-precision :; ./tests/forge/invariants/test-invariant-erc20-precision.sh
37+
test-invariant-erc20-buckets :; ./tests/forge/invariants/test-invariant-erc20-buckets.sh
38+
test-invariant-erc721-buckets :; ./tests/forge/invariants/test-invariant-erc721-buckets.sh
2239

2340
# Generate Gas Snapshots
2441
snapshot :; forge clean && forge snapshot

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ The Ajna protocol is a non-custodial, peer-to-peer, permissionless lending, borr
55
## Accepted tokens:
66
- Fungible tokens (following the [ERC20 token standard](https://eips.ethereum.org/EIPS/eip-20)).
77
- Non-fungible tokens (following the [ERC721 token standard](https://eips.ethereum.org/EIPS/eip-721))
8-
- Special considerations have been made to support specific NFTs with nonstandard ERC721 implementations, including _CryptoPunks_ and _CryptoKitties_. This support is limited to Ethereum mainnet.
98

109
### Token limitations
1110
- The following types of tokens are incompatible with Ajna, and no countermeasures exist to explicitly prevent creating a pool with such tokens, actors should use them at their own risk:
@@ -68,6 +67,13 @@ make all
6867
### Implementation notes
6968
Pool external calls carry the `nonReentrant` modifier to prevent invocation from `flashLoan` and `take` callbacks.
7069

70+
## Documentation
71+
Documentation can be generated as mdbook from Solidity NatSpecs by using `forge doc` command.
72+
For example, to generate documentation and serve it locally on port 4000 (http://localhost:4000/):
73+
```bash
74+
forge doc --serve --port 4000
75+
```
76+
7177
## Tests
7278
### Forge tests
7379
- run tests without the gas load tests (good for checking validity)

brownie-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ compiler:
1717
version: 0.8.14
1818
optimizer:
1919
enabled: true
20+
runs: 500
2021
remappings:
2122
- "@ds-math=lib/ds-math/src/"
2223
- "@openzeppelin/contracts=lib/openzeppelin-contracts/contracts"

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book/

docs/Functions.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
reverts on:
104104
- deposits locked RemoveDepositLockedByAuctionDebt()
105105
- LenderActions.removeQuoteToken():
106-
- no LPs NoClaim()
106+
- no LP NoClaim()
107107
- LUP lower than HTP LUPBelowHTP()
108108
emit events:
109109
- LenderActions.removeQuoteToken():
@@ -112,24 +112,24 @@
112112
- PoolCommons.updateInterestRate():
113113
- UpdateInterestRate
114114

115-
### transferLPs
115+
### transferLP
116116
external libraries call:
117-
- LenderActions.transferLPs()
117+
- LenderActions.transferLP()
118118

119119
write state:
120-
- LenderActions.transferLPs():
120+
- LenderActions.transferLP():
121121
- delete allowance mapping
122122
- increment new lender.lps accumulator and lender.depositTime state
123123
- delete old lender from bucket -> lender mapping
124124

125125
reverts on:
126-
- LenderActions.transferLPs():
126+
- LenderActions.transferLP():
127127
- invalid index InvalidIndex()
128128
- no allowance NoAllowance()
129129

130130
emit events:
131-
- LenderActions.transferLPs():
132-
- TransferLPs
131+
- LenderActions.transferLP():
132+
- TransferLP
133133

134134
### kick
135135
external libraries call:
@@ -232,25 +232,25 @@
232232
emit events:
233233
- BondWithdrawn
234234

235-
### startClaimableReserveAuction
235+
### kickReserveAuction
236236
external libraries call:
237-
- Auctions.startClaimableReserveAuction()
237+
- Auctions.kickReserveAuction()
238238

239239
write state:
240-
- Auctions.startClaimableReserveAuction():
240+
- Auctions.kickReserveAuction():
241241
- update reserveAuction.unclaimed accumulator
242242
- update reserveAuction.kicked timestamp state
243243
- increment latestBurnEpoch counter
244244
- update reserveAuction.latestBurnEventEpoch and burn event timestamp state
245245

246246
reverts on:
247247
- 2 weeks not passed ReserveAuctionTooSoon()
248-
- Auctions.startClaimableReserveAuction():
248+
- Auctions.kickReserveAuction():
249249
- no reserves to claim NoReserves()
250250

251251
emit events:
252-
- Auctions.startClaimableReserveAuction():
253-
- ReserveAuction
252+
- Auctions.kickReserveAuction():
253+
- KickReserveAuction
254254

255255

256256
### takeReserves
@@ -488,7 +488,7 @@
488488
- update values array state
489489
- Buckets.addCollateral():
490490
- increment bucket.collateral and bucket.lps accumulator
491-
- addLenderLPs():
491+
- addLenderLP():
492492
- increment lender.lps accumulator and lender.depositTime state
493493
- Auctions._settleAuction():
494494
- _removeAuction():
@@ -594,7 +594,7 @@
594594
- _prepareTake():
595595
- update liquidation.alreadyTaken state
596596
- _rewardBucketTake():
597-
- Buckets.addLenderLPs:
597+
- Buckets.addLenderLP:
598598
- increment taker lender.lps accumulator and lender.depositTime state
599599
- increment kicker lender.lps accumulator and lender.depositTime state
600600
- update liquidation bond size accumulator
@@ -659,7 +659,7 @@
659659
- LenderActions.addCollateral():
660660
- Buckets.addCollateral():
661661
- increment bucket.collateral and bucket.lps accumulator
662-
- addLenderLPs():
662+
- addLenderLP():
663663
- increment lender.lps accumulator and lender.depositTime state
664664
- _updateInterestState():
665665
- PoolCommons.updateInterestRate():
@@ -700,7 +700,7 @@
700700
reverts on:
701701
- LenderActions.removeCollateral():
702702
- not enough collateral InsufficientCollateral()
703-
- insufficient LPs InsufficientLPs()
703+
- insufficient LP InsufficientLP()
704704

705705
emit events:
706706
- RemoveCollateral

0 commit comments

Comments
 (0)