Skip to content

Commit

Permalink
Merge pull request #762 from ajna-finance/develop
Browse files Browse the repository at this point in the history
Merge develop in master
  • Loading branch information
grandizzy committed Apr 24, 2023
2 parents 65bcd8e + c3ec05a commit a5e00c2
Show file tree
Hide file tree
Showing 222 changed files with 18,575 additions and 8,643 deletions.
13 changes: 12 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ SOLC_VERSION=0.8.14
AJNA_TOKEN=0xaadebCF61AA7Da0573b524DE57c67aDa797D46c5

# path to the JSON keystore file for your deployment account
DEPLOY_KEY=
DEPLOY_KEY=

# Default token precisions for (invariant) testing
QUOTE_PRECISION = 18
COLLATERAL_PRECISION = 18

# Default bucket Index for (invariant) testing
BUCKET_INDEX_ERC20 = 2570
BUCKET_INDEX_ERC721 = 850

# Default no of buckets to use for (invariant) testing
NO_OF_BUCKETS = 3
8 changes: 7 additions & 1 deletion .github/workflows/forge-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ env:

jobs:
check:
env:
QUOTE_PRECISION: 18
COLLATERAL_PRECISION: 18
BUCKET_INDEX_ERC20: 2570
BUCKET_INDEX_ERC721: 850
NO_OF_BUCKETS: 3
strategy:
fail-fast: true

Expand All @@ -31,5 +37,5 @@ jobs:

- name: Run tests
run: |
make test-with-gas-report
make test-with-gas-report && make test-regression
id: test
27 changes: 22 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
# (-include to ignore error if it does not exist)
-include .env

# Default token precisions for invariant testing
QUOTE_PRECISION = 18
COLLATERAL_PRECISION = 18

# Default buckets for invariant testing
BUCKET_INDEX_ERC20 = 2570
BUCKET_INDEX_ERC721 = 850
NO_OF_BUCKETS = 3

all: clean install build

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

# Tests
test :; forge test --no-match-test "testLoad|invariant" # --ffi # enable if you need the `ffi` cheat code on HEVM
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
test-load :; FOUNDRY_PROFILE=optimized forge test --match-test testLoad --gas-report
test-invariant :; forge t --mt invariant
coverage :; forge coverage --no-match-test "testLoad|invariant"
test :; forge test --no-match-test "testLoad|invariant|test_regression" # --ffi # enable if you need the `ffi` cheat code on HEVM
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
test-load :; forge test --match-test testLoad --gas-report
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
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
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
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
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
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
coverage :; forge coverage --no-match-test "testLoad|invariant"
test-invariant-erc20-precision :; ./tests/forge/invariants/test-invariant-erc20-precision.sh
test-invariant-erc20-buckets :; ./tests/forge/invariants/test-invariant-erc20-buckets.sh
test-invariant-erc721-buckets :; ./tests/forge/invariants/test-invariant-erc721-buckets.sh

# Generate Gas Snapshots
snapshot :; forge clean && forge snapshot
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The Ajna protocol is a non-custodial, peer-to-peer, permissionless lending, borr
## Accepted tokens:
- Fungible tokens (following the [ERC20 token standard](https://eips.ethereum.org/EIPS/eip-20)).
- Non-fungible tokens (following the [ERC721 token standard](https://eips.ethereum.org/EIPS/eip-721))
- Special considerations have been made to support specific NFTs with nonstandard ERC721 implementations, including _CryptoPunks_ and _CryptoKitties_. This support is limited to Ethereum mainnet.

### Token limitations
- 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:
Expand Down Expand Up @@ -68,6 +67,13 @@ make all
### Implementation notes
Pool external calls carry the `nonReentrant` modifier to prevent invocation from `flashLoan` and `take` callbacks.

## Documentation
Documentation can be generated as mdbook from Solidity NatSpecs by using `forge doc` command.
For example, to generate documentation and serve it locally on port 4000 (http://localhost:4000/):
```bash
forge doc --serve --port 4000
```

## Tests
### Forge tests
- run tests without the gas load tests (good for checking validity)
Expand Down
1 change: 1 addition & 0 deletions brownie-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ compiler:
version: 0.8.14
optimizer:
enabled: true
runs: 500
remappings:
- "@ds-math=lib/ds-math/src/"
- "@openzeppelin/contracts=lib/openzeppelin-contracts/contracts"
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book/
34 changes: 17 additions & 17 deletions docs/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
reverts on:
- deposits locked RemoveDepositLockedByAuctionDebt()
- LenderActions.removeQuoteToken():
- no LPs NoClaim()
- no LP NoClaim()
- LUP lower than HTP LUPBelowHTP()
emit events:
- LenderActions.removeQuoteToken():
Expand All @@ -112,24 +112,24 @@
- PoolCommons.updateInterestRate():
- UpdateInterestRate

### transferLPs
### transferLP
external libraries call:
- LenderActions.transferLPs()
- LenderActions.transferLP()

write state:
- LenderActions.transferLPs():
- LenderActions.transferLP():
- delete allowance mapping
- increment new lender.lps accumulator and lender.depositTime state
- delete old lender from bucket -> lender mapping

reverts on:
- LenderActions.transferLPs():
- LenderActions.transferLP():
- invalid index InvalidIndex()
- no allowance NoAllowance()

emit events:
- LenderActions.transferLPs():
- TransferLPs
- LenderActions.transferLP():
- TransferLP

### kick
external libraries call:
Expand Down Expand Up @@ -232,25 +232,25 @@
emit events:
- BondWithdrawn

### startClaimableReserveAuction
### kickReserveAuction
external libraries call:
- Auctions.startClaimableReserveAuction()
- Auctions.kickReserveAuction()

write state:
- Auctions.startClaimableReserveAuction():
- Auctions.kickReserveAuction():
- update reserveAuction.unclaimed accumulator
- update reserveAuction.kicked timestamp state
- increment latestBurnEpoch counter
- update reserveAuction.latestBurnEventEpoch and burn event timestamp state

reverts on:
- 2 weeks not passed ReserveAuctionTooSoon()
- Auctions.startClaimableReserveAuction():
- Auctions.kickReserveAuction():
- no reserves to claim NoReserves()

emit events:
- Auctions.startClaimableReserveAuction():
- ReserveAuction
- Auctions.kickReserveAuction():
- KickReserveAuction


### takeReserves
Expand Down Expand Up @@ -488,7 +488,7 @@
- update values array state
- Buckets.addCollateral():
- increment bucket.collateral and bucket.lps accumulator
- addLenderLPs():
- addLenderLP():
- increment lender.lps accumulator and lender.depositTime state
- Auctions._settleAuction():
- _removeAuction():
Expand Down Expand Up @@ -594,7 +594,7 @@
- _prepareTake():
- update liquidation.alreadyTaken state
- _rewardBucketTake():
- Buckets.addLenderLPs:
- Buckets.addLenderLP:
- increment taker lender.lps accumulator and lender.depositTime state
- increment kicker lender.lps accumulator and lender.depositTime state
- update liquidation bond size accumulator
Expand Down Expand Up @@ -659,7 +659,7 @@
- LenderActions.addCollateral():
- Buckets.addCollateral():
- increment bucket.collateral and bucket.lps accumulator
- addLenderLPs():
- addLenderLP():
- increment lender.lps accumulator and lender.depositTime state
- _updateInterestState():
- PoolCommons.updateInterestRate():
Expand Down Expand Up @@ -700,7 +700,7 @@
reverts on:
- LenderActions.removeCollateral():
- not enough collateral InsufficientCollateral()
- insufficient LPs InsufficientLPs()
- insufficient LP InsufficientLP()

emit events:
- RemoveCollateral
Expand Down
Loading

0 comments on commit a5e00c2

Please sign in to comment.