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)
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)
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)
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)
def deploy(web3: Web3, debt_ceiling: Wad): assert isinstance(web3, Web3) vat = Vat.deploy(web3=web3) pit = Pit.deploy(web3=web3, vat=vat.address) assert pit.file_global_line(debt_ceiling).transact() # Global debt Ceiling assert vat.rely(pit.address).transact() dai = DSToken.deploy(web3=web3, symbol='DAI') dai_adapter = DaiAdapter.deploy(web3=web3, vat=vat.address, dai=dai.address) dai_move = DaiVat.deploy(web3=web3, vat=vat.address) assert vat.rely(dai_adapter.address).transact() assert vat.rely(dai_move.address).transact() mkr = DSToken.deploy(web3=web3, symbol='MKR') # TODO: use a DSProxy mom = DSGuard.deploy(web3) assert mom.permit(DSGuard.ANY, DSGuard.ANY, DSGuard.ANY).transact() assert dai.set_authority(mom.address).transact() assert mkr.set_authority(mom.address).transact() vow = Vow.deploy(web3=web3) drip = Drip.deploy(web3=web3, vat=vat.address) flap = Flapper.deploy(web3=web3, dai=dai_move.address, gem=mkr.address) assert vow.file_vat(vat).transact() assert vow.file_flap(flap).transact() assert vow.file_bump(Wad.from_number(1000)).transact() assert vow.file_sump(Wad.from_number(10)).transact() assert drip.file_vow(vow).transact() assert vat.rely(vow.address).transact() assert vat.rely(drip.address).transact() assert vat.rely(flap.address).transact() cat = Cat.deploy(web3=web3, vat=vat.address) assert cat.file_vow(vow).transact() assert cat.file_pit(pit).transact() flop = Flopper.deploy(web3=web3, dai=dai_move.address, gem=mkr.address) assert vow.file_flop(flop).transact() assert vat.rely(cat.address).transact() assert vat.rely(flop.address).transact() assert vow.rely(cat.address).transact() assert flop.rely(vow.address).transact() config = DssDeployment.Config(mom, vat, vow, drip, pit, cat, flap, flop, dai, dai_adapter, dai_move, mkr) deployment = DssDeployment(web3, config) collateral = Collateral.deploy(web3=web3, name='WETH', vat=vat) deployment.deploy_collateral(collateral, debt_ceiling=Wad.from_number(100000), penalty=Ray.from_number(1), flop_lot=Wad.from_number(10000), ratio=Ray.from_number(1.5), initial_price=Wad.from_number(219)) return deployment
def test_empty_flips(self, d: DssDeployment): nflip = d.cat.nflip() assert d.cat.flips(nflip + 1) == Cat.Flip( nflip + 1, Urn(Address('0x0000000000000000000000000000000000000000')), Wad(0))