def dent(flopper: Flopper, id: int, address: Address, lot: Wad, bid: Rad): assert (isinstance(flopper, Flopper)) assert (isinstance(id, int)) assert (isinstance(lot, Wad)) assert (isinstance(bid, Rad)) assert flopper.live() == 1 current_bid = flopper.bids(id) assert current_bid.guy != Address( "0x0000000000000000000000000000000000000000") assert current_bid.tic > datetime.now().timestamp( ) or current_bid.tic == 0 assert current_bid.end > datetime.now().timestamp() assert bid == current_bid.bid assert Wad(0) < lot < current_bid.lot assert flopper.beg() * lot <= current_bid.lot assert flopper.dent(id, lot, bid).transact(from_address=address) log = TestFlopper.last_log(flopper) assert isinstance(log, Flopper.DentLog) assert log.guy == address assert log.id == id assert log.lot == lot assert log.bid == bid
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 bids(self, id: int): return Flopper.Bid( id=id, bid=self.bid, lot=self.lot, guy=Address("0x0000000000000000000000000000000000000000"), tic=0, end=int(datetime.now(tz=timezone.utc).timestamp()) + self.tau)
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 dent(flopper: Flopper, id: int, address: Address, lot: Wad, bid: Rad): assert (isinstance(flopper, Flopper)) assert (isinstance(id, int)) assert (isinstance(lot, Wad)) assert (isinstance(bid, Rad)) assert flopper.live() == 1 current_bid = flopper.bids(id) assert current_bid.guy != Address( "0x0000000000000000000000000000000000000000") assert current_bid.tic > datetime.now().timestamp( ) or current_bid.tic == 0 assert current_bid.end > datetime.now().timestamp() assert bid == current_bid.bid assert lot < current_bid.lot assert (Wad(flopper.beg()) * lot) <= current_bid.lot assert flopper.dent(id, lot, bid).transact(from_address=address)
def setup_method(self): self.web3 = Web3(HTTPProvider("http://localhost:8555")) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.our_address = Address(self.web3.eth.defaultAccount) self.dai = DSToken.deploy(self.web3, 'DAI') self.gem = DSToken.deploy(self.web3, 'MKR') self.flopper = Flopper.deploy(self.web3, self.dai.address, self.gem.address) # so the Flopper can mint MKR dad = DSGuard.deploy(self.web3) dad.permit(self.flopper.address, self.gem.address, DSGuard.ANY).transact() self.gem.set_authority(dad.address).transact()
def setup_method(self): self.web3 = Web3(HTTPProvider("http://localhost:8555")) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.keeper_address = Address(self.web3.eth.defaultAccount) self.gal_address = Address(self.web3.eth.accounts[1]) self.other_address = Address(self.web3.eth.accounts[2]) # GemMock version of DSToken with push(bytes32, uint function) an hope(address) gem_abi = Contract._load_abi(__name__, '../lib/pymaker/tests/abi/GemMock.abi') gem_bin = Contract._load_bin(__name__, '../lib/pymaker/tests/abi/GemMock.bin') self.dai_addr = Contract._deploy(self.web3, gem_abi, gem_bin, [b'DAI']) self.dai = DSToken(web3=self.web3, address=self.dai_addr) self.dai.mint(Wad.from_number(10000000)).transact() self.dai.transfer(self.other_address, Wad.from_number(1000000)).transact() self.mkr = DSToken.deploy(self.web3, 'MKR') self.flopper = Flopper.deploy(self.web3, self.dai.address, self.mkr.address) # so the Flopper can mint MKR dad = DSGuard.deploy(self.web3) dad.permit(self.flopper.address, self.mkr.address, DSGuard.ANY).transact() self.mkr.set_authority(dad.address).transact() self.keeper = AuctionKeeper(args=args( f"--eth-from {self.keeper_address} " f"--flopper {self.flopper.address} " f"--model ./bogus-model.sh"), web3=self.web3) self.keeper.approve() self.model = MagicMock() self.model.get_stance = MagicMock(return_value=None) self.model_factory = self.keeper.auctions.model_factory self.model_factory.create_model = MagicMock(return_value=self.model)
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 last_log(flopper: Flopper): current_block = flopper.web3.eth.blockNumber return flopper.past_logs(current_block - 1, current_block)[0]
def __init__(self, flopper: Flopper): assert isinstance(flopper, Flopper) super().__init__(flopper) self.flopper = flopper self.beg = flopper.beg()
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