forked from makerdao/auction-keeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacement tuning, auto-plunge on startup, manual testing with mcd-c…
…li... (makerdao#82) * removed unmaintained testchain artifacts * break out of urn check upon Ctrl-C * updated doco * changed replacement period to three blocks * allow consuming from reservoir when amount is equal to level of reservoir * automatically plunge TX queue upon startup * bugfix * remove wait facility from the urn_cache test
- Loading branch information
Showing
31 changed files
with
165 additions
and
573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# auction-keeper manual testing | ||
|
||
The collection of python and shell scripts herein may be used to test `auction-keeper`, `pymaker`'s auction facilities, | ||
and relevant smart contracts in `dss`. Artifacts herein assume manual testing will be performed on Kovan. | ||
|
||
## Dependencies | ||
|
||
* Install `bc` and `jshon` | ||
* Install [mcd-cli](https://github.com/makerdao/mcd-cli#installation) | ||
* Configure your [environment for mcd-cli](https://github.com/makerdao/mcd-cli#configuration) | ||
* Optionally, to avoid being prompted, set `ETH_PASSWORD` to the password for your private key. | ||
|
||
## Testing flip auctions | ||
The general test workflow is: | ||
1. Procure some collateral in a vault owner account | ||
2. Procure same Dai in a keeper account | ||
3. Create "risky" vaults as close as possible to the liquidation ratio | ||
4. Run `auction-keeper` configured to bite and bid | ||
5. Periodically `drip` the `jug` to apply stability fees, causing the keeper to `bite` | ||
|
||
|
||
### Creating a single risky vault | ||
This can be done without `mcd-cli`, omitting most dependencies enumerated above. | ||
`manual_test_create_unsafe_vault.py` creates one native urn for a particular account. | ||
|
||
|
||
### Creating multiple risky vaults | ||
From the root directory of this repository, with your virtual env sourced: | ||
1. Set up your python path with `export PYTHONPATH=$PYTHONPATH:./lib/pymaker:./lib/pygasprice-client`. | ||
2. Run `mcd -C kovan --ilk=ETH-A poke` (replacing `ETH-A` with the desired collateral type) to poke the spot price. | ||
3. Run `python3 tests/manual_test_get_unsafe_vault_params.py` to determine `ink` (collateral) and `art` (Dai) for | ||
creating a vault right at the liquidation ratio. You may pass collateral type as a parameter (defaults to `ETH-A`). | ||
You may pass a desired amount of debt as a second parameter to test larger liquidations (defaults to dust limit). | ||
4. Run `tests/create-vault.sh` passing these values of `ink` and `art` to create a risky vault. You'll likely want to | ||
round up slightly to ensure there's enough collateral to generate the specified amount of Dai. Should the `draw` | ||
fail because the vault would be unsafe, call `mcd -C kovan cdp [VAULT ID] draw [ART]` drawing slightly less Dai. | ||
5. `drip` the `jug` periodically to apply stability fees, eventually creating an opportunity for the keeper to `bite`. | ||
|
||
At any time, you may run `mcd -C kovan --ilk=ETH-A cdp ls` to see a list of your vaults and | ||
`mcd -C kovan --ilk=ETH-A cdp [VAULT ID] urn` to check size and collateralization of each. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
set -e | ||
export CURRENT_DIR=$(pwd) | ||
|
||
mcd=mcd | ||
#mcd=${CURRENT_DIR}/../../mcd-cli/bin/mcd # (to run mcd-cli from source) | ||
|
||
if [ -z $2 ]; then | ||
echo "Usage: ./create-vault.sh [INK] [ART]" | ||
exit 1 | ||
fi | ||
if [ -z $ETH_FROM ]; then | ||
echo Please set ETH_FROM to the address to be used for vault creation | ||
exit 1 | ||
fi | ||
if [ -z $ETH_KEYSTORE ]; then | ||
echo Please set ETH_KEYSTORE to the directory where your private keys reside | ||
exit 1 | ||
fi | ||
if [ -z $ETH_RPC_URL ]; then | ||
echo Please set ETH_RPC_URL to your node\'s URI | ||
exit 1 | ||
fi | ||
|
||
# Amount of collateral to join and lock (Wad) | ||
ink=${1:?} | ||
# Amount of Dai to draw and exit (Wad) | ||
art=${2:?} | ||
|
||
#$mcd -C kovan wrap $ink > /dev/null | ||
id=$($mcd -C kovan --ilk=ETH-A cdp open | sed -n "s/^Opened: cdp \([0-9]\+\)$/\1/ p") > /dev/null | ||
$mcd -C kovan cdp $id lock $ink > /dev/null | ||
$mcd -C kovan cdp $id draw $art > /dev/null | ||
echo Created vault $id with ink=$ink and art=$art |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This file is part of Maker Keeper Framework. | ||
# | ||
# Copyright (C) 2020 EdNoepel | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import os | ||
import sys | ||
from web3 import Web3, HTTPProvider | ||
|
||
from pymaker.deployment import DssDeployment | ||
from pymaker.numeric import Wad, Ray, Rad | ||
|
||
|
||
# This script calculates the amount of collateral needed to produce a vault close to the liquidation ratio. | ||
# Usage: python3 tests/manual_test_get_unsafe_vault_params.py [ILK] ([TARGET_ART]) | ||
# If [TARGET_ART] is omitted, the dust cutoff is used. | ||
|
||
|
||
def r(value, decimals=1): | ||
return round(float(value), decimals) | ||
|
||
|
||
web3 = Web3(HTTPProvider(endpoint_uri=os.environ['ETH_RPC_URL'], request_kwargs={"timeout": 10})) | ||
mcd = DssDeployment.from_node(web3) | ||
collateral = mcd.collaterals[str(sys.argv[1])] if len(sys.argv) > 1 else mcd.collaterals['ETH-A'] | ||
ilk = collateral.ilk | ||
target_art = Rad.from_number(float(sys.argv[2])) if len(sys.argv) > 2 else ilk.dust | ||
osm_price = collateral.pip.peek() | ||
print(f"{ilk.name} price={osm_price}, mat={r(mcd.spotter.mat(ilk),2)}, spot={ilk.spot}, rate={ilk.rate}") | ||
|
||
# This accounts for several seconds of rate accumulation between time of calculation and the transaction being mined | ||
flub_amount = Wad(1000) | ||
ink_osm = Wad(target_art / Rad(osm_price) * Rad(mcd.spotter.mat(ilk)) * Rad(ilk.rate)) + flub_amount | ||
ink = Wad(target_art / Rad(ilk.spot) * Rad(ilk.rate)) + flub_amount | ||
if ink_osm != ink: | ||
print(f"WARNING: ink required using OSM price ({ink_osm}) does not match ink required using spot price ({ink}).") | ||
print(f"Please poke (mcd -C kovan --ilk={ilk.name} poke) to update spot price.") | ||
|
||
# art_actual = Ray(ink) * ilk.spot / ilk.rate | ||
art = Ray(target_art) | ||
collat_ratio = Ray(ink) * Ray(osm_price) / (art * ilk.rate) | ||
|
||
print(f"frob with ink={ink} {ilk.name}, art={art} Dai for {r(collat_ratio*100,6)}% collateralization") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.