Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert on remove collateral if not enough LPs #613

Merged
merged 7 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

<!---
No need to add special tag
src/ & non src/ changes you need the following (that apply):
-->
# Description of change
## High level
* <DESCRIP_OF_CHANGE>
* <DESCRIP_OF_SUBCHANGE>

<!---
Add the `Status: Needs Auditor Approval` tags
CHANGES IN /SRC DIR:
- renaming (not retyping or resizing) of variables & methods
- reordering and moving of functions in files
- lite moving of functions accross files
- comments

src/ changes you need the following (that apply):
-->

# Description of bug or vulnerability and solution
* <PARAGRAPH_EXP_OF_VULN_BUG>
* <PARAGRAPH_EXP_OF_HOW_CHANGE_SOLVES_VULN_OR_BUG>

# Contract size
## Pre Change
<PASTE_OUTPUT_HERE>
## Post Change
<PASTE_OUTPUT_HERE>

# Gas usage
## Pre Change
<PASTE_OUTPUT_HERE>
## Post Change
<PASTE_OUTPUT_HERE>

2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

# Report code coverage to discord
- name: Generate coverage
run: forge coverage --report lcov --no-match-test testLoad
run: forge coverage --report lcov --no-match-test "testLoad|invariant"
- name: Setup LCOV
uses: hrishikesh-kadam/setup-lcov@v1
- name: Filter lcov
Expand Down
55 changes: 0 additions & 55 deletions .github/workflows/forge-tests.yml

This file was deleted.

17 changes: 9 additions & 8 deletions .github/workflows/size-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
submodules: recursive

- name: Cache compiler installations
uses: actions/cache@v2
id: cache-compiler
uses: actions/cache@v3
with:
path: |
~/.solcx
Expand All @@ -32,13 +33,13 @@ jobs:
- name: Set pip cache directory path
id: pip-cache-dir-path
run: |
echo "::set-output name=dir::$(pip cache dir)"
echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV
- name: Restore pip cache
uses: actions/cache@v2
uses: actions/cache@v3
id: pip-cache
with:
path: |
${{ steps.pip-cache-dir-path.outputs.dir }}
${PIP_CACHE_DIR}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
Expand All @@ -47,17 +48,17 @@ jobs:
run: pip install -r requirements-dev.txt

- name: Run check-size script
id: check-size
run: |
mkdir -p size-reports-${{ github.run_id }}
./check-size.sh | tee size-reports-${{github.run_id}}/size-report
echo "##[set-output name=size-report;]$(echo $(cat size-reports-${{github.run_id}}/size-report|tail -1))"
id: check-size
echo "SIZE_REPORT=$(echo $(cat size-reports-${{github.run_id}}/size-report|tail -1))" >> $GITHUB_OUTPUT

- name: Send size report to Discord
uses: appleboy/discord-action@master
with:
webhook_id: ${{ secrets.DISCORD_ID }}
webhook_token: ${{ secrets.DISCORD_TOKEN }}
username: "Contract Size Reporter"
message: Largest contract size for `${{ github.ref }}` ```${{ steps.check-size.outputs.size-report }}```
timeout-minutes: 2
message: Largest contract size for `${{ github.ref }}` ```${{ steps.check-size.outputs.SIZE_REPORT }}```
timeout-minutes: 3
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ reports/
coverage/
*.info
report/
keystore/
keystore/
broadcast/
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ install :; git submodule update --init --recursive
build :; forge clean && forge build

# Tests
test :; forge test --no-match-test testLoad # --ffi # enable if you need the `ffi` cheat code on HEVM
test-with-gas-report :; FOUNDRY_PROFILE=optimized forge test --no-match-test testLoad --gas-report # --ffi # enable if you need the `ffi` cheat code on HEVM
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
coverage :; forge coverage --no-match-test testLoad
test-invariant :; forge t --mt invariant
coverage :; forge coverage --no-match-test "testLoad|invariant"

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

analyze:
slither src/. ; slither src/libraries/external/.


# Deployment
deploy-contracts:
forge script ./deploy.sol \
--rpc-url ${ETH_RPC_URL} --sender ${DEPLOY_ADDRESS} --keystore ${DEPLOY_KEY} --broadcast -vvv
60 changes: 34 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

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. The protocol consists of pools: pairings of quote tokens provided by lenders and collateral tokens provided by borrowers. Ajna is capable of accepting fungible tokens as quote tokens and both fungible and non-fungible tokens as collateral tokens.

## Limitations
- The following types of tokens are incompatible with Ajna, and no countermeasures exist to explicitly prevent creating a pool with such tokens:
- Fungible tokens whose balance rebases.
- NFTs which charge a fee on transfer.
- Fungible tokens with more than 18 decimals or 0 decimals.
## 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:
- NFT and fungible tokens which charge a fee on transfer.
- Fungible tokens whose balance rebases.
- Fungible tokens with more than 18 decimals or 0 decimals.
- Borrowers cannot draw debt from a pool in the same block as when the pool was created.
- With the exception of quantized prices, pool inputs and most accumulators are not explicitly limited. The pool will stop functioning when the bounds of a `uint256` need to be exceeded to process a request.



## Development
### Requirements
- `python` 3.0+
Expand Down Expand Up @@ -150,35 +155,38 @@ Modifications to, or notices of actions by Licensor, contemplated above or under

## Deployment

A deployment script has been created to automate deployment of libraries and factory contracts.
To use it, set up an environment with the following:
- **AJNA_TOKEN** - address of the AJNA token on your target chain
- **ETH_RPC_URL** - node pointing to the target chain
- **DEPLOY_KEY** - path to the JSON keystore file for your deployment account
A deployment script has been created to automate deployment of libraries, factory contracts, and manager contracts.

To use it, ensure the following env variables are in your `.env` file or exported into your environment.
| Environment Variable | Purpose |
|----------------------|---------|
| `AJNA_TOKEN` | address of the AJNA token on your target chain
| `DEPLOY_ADDRESS` | address from which you wish to deploy
| `DEPLOY_KEY` | path to the JSON keystore file for the deployment address
| `ETHERSCAN_API_KEY` | required to verify contracts
| `ETH_RPC_URL` | node on your target deployment network

Ensure your deployment account is funded with some ETH for gas.

The deployment script takes no arguments, and interactively prompts for your keystore password:
Since contract source has not yet been made public, the `--verify` switch has been omitted. To run:

```
./deploy.sh
make deploy-contracts
```

Upon completion, contract addresses will be printed to `stdout`:
```
Deploying to chain with AJNA token address 0xDD576260ed60AaAb798D8ECa9bdBf33D70E077F4
Enter keystore password:
Deploying libraries...
Deployed Auctions to 0xDD576260ed60AaAb798D8ECa9bdBf33D70E077F4
Deployed LenderActions to 0x4c08A2ec1f5C067DC53A5fCc36C649501F403b93
Deployed PoolCommons to 0x8BBCA51044d00dbf16aaB8Fd6cbC5B45503B898b
Deploying factories...
Deployed ERC20PoolFactory to 0xED625fbf62695A13d2cADEdd954b23cc97249988
Deployed ERC721PoolFactory to 0x775D30918A42160bC7aE56BA1660E32ff50CF6dC
Deploying PoolInfoUtils...
Deployed PoolInfoUtils to 0xd8A51cE16c7665111401C0Ba2ABEcE03B847b4e6
== Logs ==
Deploying to chain with AJNA token address 0x34A1D3fff3958843C43aD80F30b94c510645C...
=== Deployment addresses ===
ERC20 factory 0x50EEf481cae4250d252Ae577A09bF514f224C...
ERC721 factory 0x62c20Aa1e0272312BC100b4e23B4DC1Ed96dD...
PoolInfoUtils 0xDEb1E9a6Be7Baf84208BB6E10aC9F9bbE1D70...
PositionManager 0xD718d5A27a29FF1cD22403426084bA0d47986...
RewardsManager 0x4f559F30f5eB88D635FDe1548C4267DB8FaB0...

```

Record the factory addresses.
Record these addresses.

### Validation

Expand All @@ -203,4 +211,4 @@ cast send ${DAI_TOKEN} "approve(address,uint256)" ${WBTC_DAI_POOL} 50000ether \
--from ${DEPLOY_ADDRESS} --keystore ${DEPLOY_KEY}
cast send ${WBTC_DAI_POOL} "addQuoteToken(uint256,uint256)" 100ether 3232 \
--from ${DEPLOY_ADDRESS} --keystore ${DEPLOY_KEY}
```
```
2 changes: 1 addition & 1 deletion check-code-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

forge coverage --report lcov --no-match-test testLoad
forge coverage --report lcov --no-match-test "testLoad|invariant"

lcov -r lcov.info "tests/*" -o lcov-filtered.info --rc lcov_branch_coverage=1

Expand Down
63 changes: 0 additions & 63 deletions deploy.sh

This file was deleted.

36 changes: 36 additions & 0 deletions deploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.14;

import { Script } from "forge-std/Script.sol";
import "forge-std/console.sol";

import { ERC20PoolFactory } from 'src/ERC20PoolFactory.sol';
import { ERC721PoolFactory } from 'src/ERC721PoolFactory.sol';
import { PoolInfoUtils } from 'src/PoolInfoUtils.sol';
import { PositionManager } from 'src/PositionManager.sol';
import { RewardsManager } from 'src/RewardsManager.sol';

contract Deploy is Script {
address ajna;

function run() public {
ajna = vm.envAddress("AJNA_TOKEN");
console.log("Deploying to chain with AJNA token address %s", ajna);

vm.startBroadcast();
ERC20PoolFactory erc20factory = new ERC20PoolFactory(ajna);
ERC721PoolFactory erc721factory = new ERC721PoolFactory(ajna);
PoolInfoUtils poolInfoUtils = new PoolInfoUtils();

PositionManager positionManager = new PositionManager(erc20factory, erc721factory);
RewardsManager rewardsManager = new RewardsManager(ajna, positionManager);
vm.stopBroadcast();

console.log("=== Deployment addresses ===");
console.log("ERC20 factory %s", address(erc20factory));
console.log("ERC721 factory %s", address(erc721factory));
console.log("PoolInfoUtils %s", address(poolInfoUtils));
console.log("PositionManager %s", address(positionManager));
console.log("RewardsManager %s", address(rewardsManager));
}
}
Loading