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 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])
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])
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 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))
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
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 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]))
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()])
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()])
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])
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()])
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())
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())
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))
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())
def tag(self, ilk: Ilk) -> Ray: """Cage price for the collateral""" assert isinstance(ilk, Ilk) return Ray(self._contract.functions.tag(ilk.toBytes()).call())
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)
def ilk(self): return Ilk.fromBytes(self._contract.functions.ilk().call())
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])
def art(self, ilk: Ilk) -> Wad: """Total debt for the collateral""" assert isinstance(ilk, Ilk) return Wad(self._contract.functions.Art(ilk.toBytes()).call())
def ilk(self): return Ilk.fromBytes(self._contract.call().ilk())
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