Example #1
0
 def from_json(web3: Web3, conf: str):
     conf = json.loads(conf)
     mom = DSGuard(web3, Address(conf['MCD_MOM']))
     vat = Vat(web3, Address(conf['MCD_VAT']))
     vow = Vow(web3, Address(conf['MCD_VOW']))
     drip = Drip(web3, Address(conf['MCD_DRIP']))
     pit = Pit(web3, Address(conf['MCD_PIT']))
     cat = Cat(web3, Address(conf['MCD_CAT']))
     flap = Flapper(web3, Address(conf['MCD_FLAP']))
     flop = Flopper(web3, Address(conf['MCD_FLOP']))
     dai = DSToken(web3, Address(conf['MCD_DAI']))
     dai_adapter = DaiAdapter(web3, Address(conf['MCD_JOIN_DAI']))
     dai_move = DaiVat(web3, Address(conf['MCD_MOVE_DAI']))
     mkr = DSToken(web3, Address(conf['MCD_GOV']))
     collaterals = []
     for name in conf['COLLATERALS']:
         collateral = Collateral(Ilk(name))
         collateral.gem = DSToken(web3, Address(conf[name]))
         collateral.adapter = GemAdapter(web3, Address(conf[f'MCD_JOIN_{name}']))
         collateral.mover = GemVat(web3, Address(conf[f'MCD_MOVE_{name}']))
         collateral.flipper = Flipper(web3, Address(conf[f'MCD_FLIP_{name}']))
         collateral.pip = DSValue(web3, Address(conf[f'PIP_{name}']))
         collateral.spotter = Spotter(web3, Address(conf[f'MCD_SPOT_{name}']))
         collaterals.append(collateral)
     return DssDeployment.Config(mom, vat, vow, drip, pit, cat, flap, flop, dai, dai_adapter, dai_move, mkr,
                                 collaterals)
Example #2
0
 def skim(self, ilk: Ilk, address: Address) -> Transact:
     """Cancels undercollateralized CDP debt to determine collateral shortfall"""
     assert isinstance(ilk, Ilk)
     assert isinstance(address, Address)
     return Transact(self, self.web3, self.abi, self.address,
                     self._contract, 'skim',
                     [ilk.toBytes(), address.address])
Example #3
0
    def open(self, ilk: Ilk, address: Address) -> Transact:
        assert isinstance(ilk, Ilk)
        assert isinstance(address, Address)

        return Transact(self, self.web3, self.abi, self.address,
                        self._contract, 'open',
                        [ilk.toBytes(), address.address])
Example #4
0
        def from_json(web3: Web3, conf: str):
            conf = json.loads(conf)
            pause = DSPause(web3, Address(conf['MCD_PAUSE']))
            vat = Vat(web3, Address(conf['MCD_VAT']))
            vow = Vow(web3, Address(conf['MCD_VOW']))
            jug = Jug(web3, Address(conf['MCD_JUG']))
            cat = Cat(web3, Address(conf['MCD_CAT']))
            dai = DSToken(web3, Address(conf['MCD_DAI']))
            dai_adapter = DaiJoin(web3, Address(conf['MCD_JOIN_DAI']))
            flapper = Flapper(web3, Address(conf['MCD_FLAP']))
            flopper = Flopper(web3, Address(conf['MCD_FLOP']))
            mkr = DSToken(web3, Address(conf['MCD_GOV']))
            spotter = Spotter(web3, Address(conf['MCD_SPOT']))

            collaterals = {}
            for name in DssDeployment.Config._infer_collaterals_from_addresses(conf.keys()):
                ilk = Ilk(name[0].replace('_', '-'))
                if name[1] == "ETH":
                    gem = DSEthToken(web3, Address(conf[name[1]]))
                else:
                    gem = DSToken(web3, Address(conf[name[1]]))

                # TODO: If problematic, skip pip for deployments which use a medianizer.
                collateral = Collateral(ilk=ilk, gem=gem,
                                        adapter=GemJoin(web3, Address(conf[f'MCD_JOIN_{name[0]}'])),
                                        flipper=Flipper(web3, Address(conf[f'MCD_FLIP_{name[0]}'])),
                                        pip=DSValue(web3, Address(conf[f'PIP_{name[1]}'])))
                collaterals[ilk.name] = collateral

            return DssDeployment.Config(pause, vat, vow, jug, cat, flapper, flopper,
                                        dai, dai_adapter, mkr, spotter, collaterals)
Example #5
0
 def test_ilk(self, mcd):
     assert mcd.vat.ilk('XXX') == Ilk('XXX',
                                      rate=Ray(0),
                                      ink=Wad(0),
                                      art=Wad(0),
                                      spot=Ray(0),
                                      line=Rad(0),
                                      dust=Rad(0))
Example #6
0
    def test_ilk(self, mcd):
        assert mcd.vat.ilk('XXX') == Ilk('XXX',
                                         rate=Ray(0), ink=Wad(0), art=Wad(0), spot=Ray(0), line=Rad(0), dust=Rad(0))

        ilk = mcd.collaterals["ETH-C"].ilk
        assert ilk.line == Rad.from_number(1000000)
        assert ilk.dust == Rad.from_number(20)

        representation = repr(ilk)
        assert "ETH-C" in representation
Example #7
0
        def from_json(web3: Web3, conf: str):
            conf = json.loads(conf)
            pause = DSPause(web3, Address(conf['MCD_PAUSE']))
            vat = Vat(web3, Address(conf['MCD_VAT']))
            vow = Vow(web3, Address(conf['MCD_VOW']))
            jug = Jug(web3, Address(conf['MCD_JUG']))
            cat = Cat(web3, Address(conf['MCD_CAT']))
            dai = DSToken(web3, Address(conf['MCD_DAI']))
            dai_adapter = DaiJoin(web3, Address(conf['MCD_JOIN_DAI']))
            flapper = Flapper(web3, Address(conf['MCD_FLAP']))
            flopper = Flopper(web3, Address(conf['MCD_FLOP']))
            pot = Pot(web3, Address(conf['MCD_POT']))
            mkr = DSToken(web3, Address(conf['MCD_GOV']))
            spotter = Spotter(web3, Address(conf['MCD_SPOT']))
            ds_chief = DSChief(web3, Address(conf['MCD_ADM']))
            esm = ShutdownModule(web3, Address(conf['MCD_ESM']))
            end = End(web3, Address(conf['MCD_END']))
            proxy_registry = ProxyRegistry(web3,
                                           Address(conf['PROXY_REGISTRY']))
            dss_proxy_actions = DssProxyActionsDsr(
                web3, Address(conf['PROXY_ACTIONS_DSR']))

            collaterals = {}
            for name in DssDeployment.Config._infer_collaterals_from_addresses(
                    conf.keys()):
                ilk = Ilk(name[0].replace('_', '-'))
                if name[1] == "ETH":
                    gem = DSEthToken(web3, Address(conf[name[1]]))
                else:
                    gem = DSToken(web3, Address(conf[name[1]]))

                # PIP contract may be a DSValue, OSM, or bogus address.
                pip_address = Address(conf[f'PIP_{name[1]}'])
                network = DssDeployment.NETWORKS.get(web3.net.version,
                                                     "testnet")
                if network == "testnet":
                    pip = DSValue(web3, pip_address)
                else:
                    pip = OSM(web3, pip_address)

                collateral = Collateral(
                    ilk=ilk,
                    gem=gem,
                    adapter=GemJoin(web3,
                                    Address(conf[f'MCD_JOIN_{name[0]}'])),
                    flipper=Flipper(web3,
                                    Address(conf[f'MCD_FLIP_{name[0]}'])),
                    pip=pip)
                collaterals[ilk.name] = collateral

            return DssDeployment.Config(pause, vat, vow, jug, cat, flapper,
                                        flopper, pot, dai, dai_adapter, mkr,
                                        spotter, ds_chief, esm, end,
                                        proxy_registry, dss_proxy_actions,
                                        collaterals)
Example #8
0
    def deploy(web3: Web3, vat: Address, ilk: Ilk, gem: Address):
        assert isinstance(web3, Web3)
        assert isinstance(vat, Address)
        assert isinstance(ilk, Ilk)
        assert isinstance(gem, Address)

        return GemMock(
            web3=web3,
            address=Contract._deploy(
                web3, GemMock.abi, GemMock.bin,
                [vat.address, ilk.toBytes(), gem.address]))
Example #9
0
 def flow(self, ilk: Ilk) -> Transact:
     """Calculate the `fix`, the cash price for a given collateral"""
     assert isinstance(ilk, Ilk)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'flow', [ilk.toBytes()])
Example #10
0
 def free(self, ilk: Ilk) -> Transact:
     """Releases excess collateral after `skim`ming"""
     assert isinstance(ilk, Ilk)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'free', [ilk.toBytes()])
Example #11
0
 def skip(self, ilk: Ilk, flip_id: int) -> Transact:
     """Cancel a flip auction and seize it's collateral"""
     assert isinstance(ilk, Ilk)
     assert isinstance(flip_id, int)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'skip', [ilk.toBytes(), flip_id])
Example #12
0
 def cage(self, ilk: Ilk) -> Transact:
     """Set the `cage` price for the collateral"""
     assert isinstance(ilk, Ilk)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'cage(bytes32)', [ilk.toBytes()])
Example #13
0
 def out(self, ilk: Ilk, address: Address) -> Wad:
     assert isinstance(ilk, Ilk)
     assert isinstance(address, Address)
     return Wad(self._contract.functions.out(ilk.toBytes(), address.address).call())
Example #14
0
 def fix(self, ilk: Ilk) -> Ray:
     """Final cash price for the collateral"""
     assert isinstance(ilk, Ilk)
     return Ray(self._contract.functions.fix(ilk.toBytes()).call())
Example #15
0
 def test_ilk(self, d: DssDeployment):
     assert d.vat.ilk('XXX') == Ilk('XXX',
                                    take=Ray(0),
                                    rate=Ray(0),
                                    ink=Wad(0),
                                    art=Wad(0))
Example #16
0
 def gap(self, ilk: Ilk) -> Wad:
     """Collateral shortfall (difference of debt and collateral"""
     assert isinstance(ilk, Ilk)
     return Wad(self._contract.functions.gap(ilk.toBytes()).call())
Example #17
0
 def tag(self, ilk: Ilk) -> Ray:
     """Cage price for the collateral"""
     assert isinstance(ilk, Ilk)
     return Ray(self._contract.functions.tag(ilk.toBytes()).call())
Example #18
0
    def test_rely(self, d: DssDeployment, other_address: Address):
        # when
        assert d.vat.rely(other_address).transact()

        # then
        assert d.vat.init(Ilk('ETH')).transact(from_address=other_address)
Example #19
0
 def ilk(self):
     return Ilk.fromBytes(self._contract.functions.ilk().call())
Example #20
0
 def cash(self, ilk: Ilk, dai: Wad):
     """Exchange an amount of dai (already `pack`ed in the `bag`) for collateral"""
     assert isinstance(ilk, Ilk)
     assert isinstance(dai, Wad)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'cash', [ilk.toBytes(), dai.value])
Example #21
0
 def art(self, ilk: Ilk) -> Wad:
     """Total debt for the collateral"""
     assert isinstance(ilk, Ilk)
     return Wad(self._contract.functions.Art(ilk.toBytes()).call())
Example #22
0
 def ilk(self):
     return Ilk.fromBytes(self._contract.call().ilk())
Example #23
0
    def ilk(self, cdpid: int) -> Ilk:
        '''Returns Ilk for respective CDP ID'''
        assert isinstance(cdpid, int)

        ilk = Ilk.fromBytes(self._contract.functions.ilks(cdpid).call())
        return ilk