Ejemplo n.º 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)
Ejemplo n.º 2
0
    def deploy_collateral(self, collateral: Collateral,
                          debt_ceiling: Wad, penalty: Ray, flop_lot: Wad, ratio: Ray, initial_price: Wad):

        collateral.pip = DSValue.deploy(web3=self.web3)
        assert collateral.pip.poke_with_int(initial_price.value).transact()  # Initial price

        collateral.flipper = Flipper.deploy(web3=self.web3, dai=self.dai_move.address, gem=collateral.mover.address)

        collateral.spotter = Spotter.deploy(web3=self.web3, pit=self.pit.address, ilk=collateral.ilk)
        collateral.spotter.file_pip(collateral.pip.address).transact()
        collateral.spotter.file_mat(ratio).transact()  # Liquidation ratio

        assert collateral.gem.approve(collateral.adapter.address).transact()

        assert self.cat.file_flip(collateral.ilk, collateral.flipper).transact()
        assert self.cat.file_lump(collateral.ilk, flop_lot).transact()  # Liquidation Quantity
        assert self.cat.file_chop(collateral.ilk, penalty).transact()  # Liquidation Penalty
        assert self.vat.init(collateral.ilk).transact()
        assert self.drip.init(collateral.ilk).transact()

        assert self.vat.rely(collateral.flipper.address).transact()
        assert self.vat.rely(collateral.adapter.address).transact()
        assert self.vat.rely(collateral.mover.address).transact()
        assert self.pit.rely(collateral.spotter.address).transact()

        assert self.pit.file_line(collateral.ilk, debt_ceiling).transact()  # Collateral debt Ceiling
        assert collateral.spotter.poke().transact()

        self.collaterals.append(collateral)
Ejemplo n.º 3
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)
Ejemplo n.º 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']))
            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)
Ejemplo n.º 5
0
        def from_json(web3: Web3, conf: str):
            def address_in_configs(key: str, conf: str) -> bool:
                if key not in conf:
                    return False
                elif not conf[key]:
                    return False
                elif conf[key] == "0x0000000000000000000000000000000000000000":
                    return False
                else:
                    return True

            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'])) if address_in_configs(
                'MCD_CAT', conf) else None
            dog = Dog(web3, Address(conf['MCD_DOG'])) if address_in_configs(
                'MCD_DOG', conf) else None
            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']))
            cdp_manager = CdpManager(web3, Address(conf['CDP_MANAGER']))
            dsr_manager = DsrManager(web3, Address(conf['DSR_MANAGER']))
            faucet = TokenFaucet(
                web3, Address(conf['FAUCET'])) if address_in_configs(
                    'FAUCET', conf) else None

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

                if name[1] in [
                        'USDC', 'WBTC', 'TUSD', 'USDT', 'GUSD', 'RENBTC'
                ]:
                    adapter = GemJoin5(web3,
                                       Address(conf[f'MCD_JOIN_{name[0]}']))
                else:
                    adapter = GemJoin(web3,
                                      Address(conf[f'MCD_JOIN_{name[0]}']))

                # PIP contract may be a DSValue, OSM, or bogus address.
                pip_name = f'PIP_{name[1]}'
                pip_address = Address(
                    conf[pip_name]
                ) if pip_name in conf and conf[pip_name] else None
                val_name = f'VAL_{name[1]}'
                val_address = Address(
                    conf[val_name]
                ) if val_name in conf and conf[val_name] else None
                if pip_address:  # Configure OSM as price source
                    if name[1].startswith('UNIV2'):
                        pip = Univ2LpOSM(web3, pip_address)
                    else:
                        pip = OSM(web3, pip_address)
                elif val_address:  # Configure price using DSValue
                    pip = DSValue(web3, val_address)
                else:
                    pip = None

                auction = None
                if f'MCD_FLIP_{name[0]}' in conf:
                    auction = Flipper(web3,
                                      Address(conf[f'MCD_FLIP_{name[0]}']))
                elif f'MCD_CLIP_{name[0]}' in conf:
                    auction = Clipper(web3,
                                      Address(conf[f'MCD_CLIP_{name[0]}']))

                collateral = Collateral(ilk=ilk,
                                        gem=gem,
                                        adapter=adapter,
                                        auction=auction,
                                        pip=pip,
                                        vat=vat)
                collaterals[ilk.name] = collateral

            return DssDeployment.Config(pause, vat, vow, jug, cat, dog,
                                        flapper, flopper, pot, dai,
                                        dai_adapter, mkr, spotter, ds_chief,
                                        esm, end, proxy_registry,
                                        dss_proxy_actions, cdp_manager,
                                        dsr_manager, faucet, collaterals)