def liquidate_urn(cls, web3, mcd, c, gal_address, our_address): # Ensure the CDP isn't safe urn = mcd.vat.urn(c.ilk, gal_address) dart = max_dart(mcd, c, gal_address) - Wad.from_number(1) assert mcd.vat.frob(c.ilk, gal_address, Wad(0), dart).transact(from_address=gal_address) set_collateral_price(mcd, c, Wad.from_number(66)) assert not is_cdp_safe(mcd.vat.ilk(c.ilk.name), urn) # Determine how many bites will be required dunk = Wad(mcd.cat.dunk(c.ilk)) urn = mcd.vat.urn(c.ilk, gal_address) bites_required = math.ceil(urn.art / dunk) print(f"art={urn.art} and dunk={dunk} so {bites_required} bites are required") c.flipper.approve(mcd.vat.address, approval_function=hope_directly(from_address=our_address)) first_kick = c.flipper.kicks() + 1 # Bite and bid on each auction for i in range(bites_required): kick = bite(mcd, c, urn) assert kick > 0 auction = c.flipper.bids(kick) print(f"biting {i} of {bites_required} and bidding tab of {auction.tab}") bid = Wad(auction.tab) + Wad(1) reserve_dai(mcd, c, our_address, bid) print(f"bidding tab of {auction.tab}") assert c.flipper.tend(kick, auction.lot, auction.tab).transact(from_address=our_address) time_travel_by(web3, c.flipper.ttl()) for kick in range(first_kick, c.flipper.kicks()): assert c.flipper.deal(kick).transact() set_collateral_price(mcd, c, Wad.from_number(200)) urn = mcd.vat.urn(c.ilk, gal_address)
def liquidate_urn(cls, web3, mcd, c, gal_address, our_address): # Ensure the CDP isn't safe urn = mcd.vat.urn(c.ilk, gal_address) dart = max_dart(mcd, c, gal_address) - Wad.from_number(1) assert mcd.vat.frob(c.ilk, gal_address, Wad(0), dart).transact(from_address=gal_address) set_collateral_price(mcd, c, Wad.from_number(66)) assert not is_cdp_safe(mcd.vat.ilk(c.ilk.name), urn) # Bite and kick off the auction kick = bite(mcd, c, urn) assert kick > 0 # Bid on and win the auction auction = c.flipper.bids(kick) bid = Wad(auction.tab) + Wad(1) reserve_dai(mcd, c, our_address, bid) c.flipper.approve( mcd.vat.address, approval_function=hope_directly(from_address=our_address)) assert c.flipper.tend(kick, auction.lot, auction.tab).transact(from_address=our_address) time_travel_by(web3, c.flipper.ttl() + 1) assert c.flipper.deal(kick).transact() set_collateral_price(mcd, c, Wad.from_number(200)) urn = mcd.vat.urn(c.ilk, gal_address) assert urn.ink == Wad(0) assert urn.art == Wad(0)
def create_risky_vault(): # Create a vault close to the liquidation ratio if not is_cdp_safe(mcd.vat.ilk(collateral.ilk.name), urn): logging.info("Vault is already unsafe; no action taken") else: collateral_amount = Wad(ilk.dust / Rad(ilk.spot) * Rad(ilk.rate)) + flub_amount logging.info(f"Opening/adjusting vault with {collateral_amount} {ilk.name}") create_risky_cdp(mcd, collateral, collateral_amount, our_address, False) logging.info("Created risky vault")
def create_risky_vault(): # Create a vault close to the liquidation ratio if not is_cdp_safe(mcd.vat.ilk(collateral.ilk.name), urn): print("Vault is already unsafe; no action taken") else: osm_price = collateral.pip.peek() print(f"dust={ilk.dust} osm_price={osm_price} mat={mcd.spotter.mat(ilk)}") # To make a (barely) safe urn, I expected to add 10^-8, but for some reason I need to add 10^-7 normalized_collateral_amount = (Wad(ilk.dust) / osm_price * Wad(mcd.spotter.mat(ilk))) + Wad.from_number(0.00000050) # token = Token(ilk.name, collateral.gem.address, collateral.adapter.dec()) print(f"Opening vault with {normalized_collateral_amount} {ilk.name}") create_risky_cdp(mcd, collateral, Wad.from_number(normalized_collateral_amount), our_address, True) print("Created unsafe vault")
# (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 sys from pymaker.numeric import Wad, Ray, Rad from tests.conftest import create_unsafe_cdp, is_cdp_safe, mcd, gal_address, web3 mcd = mcd(web3()) address = gal_address(web3()) collateral_amount = Wad.from_number(float( sys.argv[1])) if len(sys.argv) > 1 else 1.0 collateral = mcd.collaterals[str( sys.argv[2])] if len(sys.argv) > 2 else mcd.collaterals['ETH-C'] urn = mcd.vat.urn(collateral.ilk, address) if not is_cdp_safe(mcd.vat.ilk(collateral.ilk.name), urn): print("CDP is already unsafe; no action taken") else: create_unsafe_cdp(mcd, collateral, Wad.from_number(collateral_amount), address, False) print("Created unsafe CDP")