def bite(self, ilk_id, urn, now):
        # TODO: Remove `now` once better timekeeping solution is implemented

        rate = self.vat.ilks[ilk_id].rate
        spot = self.vat.ilks[ilk_id].spot
        dust = self.vat.ilks[ilk_id].dust
        ink = self.vat.urns[ilk_id][urn].ink
        art = self.vat.urns[ilk_id][urn].art

        require(spot > Ray(0) and Rad(ink * spot) < Rad(art * rate),
                "Cat/not-unsafe")

        milk = self.ilks[ilk_id]

        room = self.box - self.litter
        require(self.litter < self.box and room >= dust,
                "Cat/liquidation-limit-hit")

        dart = Wad.min(art,
                       Wad(Rad.min(milk.dunk, room)) / Wad(rate) / milk.chop)
        dink = Wad.min(ink, ink * dart / art)

        require(dart > Wad(0) and dink > Wad(0), "Cat/null-auction")
        require(
            dart <= Wad.from_number(2**255)
            and dink <= Wad.from_number(2**255),
            "Cat/overflow",
        )

        self.vat.grab(ilk_id, urn, self.ADDRESS, self.vow.ADDRESS,
                      Wad(0) - dink,
                      Wad(0) - dart)
        self.vow.fess(Rad(dart * rate), now)

        tab = Rad(dart * rate * milk.chop)
        self.litter += tab

        milk.flip.kick(urn, self.vow.ADDRESS, tab, dink, Rad(0), now)
Beispiel #2
0
    def place_bid(self, bid_id, price, ilk_id, now):
        if price > Wad(0):
            flipper = self.flippers[ilk_id]
            bid = flipper.bids[bid_id]

            if bid.bid == bid.tab:
                # Dent phase
                our_lot = Wad(bid.bid / Rad(price))
                if (our_lot * flipper.beg <= bid.lot and our_lot < bid.lot
                        and self.vat.dai.get(self.ADDRESS)
                        and self.vat.dai[self.ADDRESS] >= bid.bid):
                    return {
                        "key": "DENT",
                        "keeper": self,
                        "handler": flipper.dent,
                        "args": [bid_id, self.ADDRESS, our_lot, bid.bid, now],
                        "kwargs": {},
                    }

            else:
                # Tend phase
                our_bid = Rad.min(Rad(bid.lot) * price, bid.tab)
                if ((our_bid >= bid.bid * flipper.beg or our_bid == bid.tab)
                        and our_bid > bid.bid
                        and self.vat.dai.get(self.ADDRESS)
                        and self.vat.dai[self.ADDRESS] >=
                    (our_bid if self.ADDRESS != bid.guy else our_bid -
                     bid.bid)):
                    return {
                        "key": "TEND",
                        "keeper": self,
                        "handler": flipper.tend,
                        "args": [bid_id, self.ADDRESS, bid.lot, our_bid, now],
                        "kwargs": {},
                    }

        return None