def dent(flipper: Flipper, id: int, address: Address, lot: Wad, bid: Rad): assert (isinstance(flipper, Flipper)) assert (isinstance(id, int)) assert (isinstance(lot, Wad)) assert (isinstance(bid, Rad)) current_bid = flipper.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 bid == current_bid.tab assert lot < current_bid.lot assert flipper.beg() * lot <= current_bid.lot assert flipper.dent(id, lot, bid).transact(from_address=address)
def tend_with_dai(mcd: DssDeployment, c: Collateral, flipper: Flipper, id: int, address: Address, bid: Rad): assert (isinstance(mcd, DssDeployment)) assert (isinstance(c, Collateral)) assert (isinstance(flipper, Flipper)) assert (isinstance(id, int)) assert (isinstance(bid, Rad)) flipper.approve(flipper.vat(), approval_function=hope_directly(from_address=address)) previous_bid = flipper.bids(id) c.approve(address) reserve_dai(mcd, c, address, Wad(bid), extra_collateral=Wad.from_number(2)) TestAuctionKeeperFlipper.tend(flipper, id, address, previous_bid.lot, bid)
def test_flip(self, web3, d: DssDeployment, bite_event): # given nflip = d.cat.nflip() flipper = Flipper(web3=web3, address=d.cat.flipper(bite_event.ilk)) kicks = flipper.kicks() # when assert nflip > 0 flip = d.cat.flips(nflip - 1) assert flip.tab > Wad(0) lump = d.cat.lump(flip.urn.ilk) if flip.tab < lump: assert d.cat.flip(flip, flip.tab).transact() else: assert d.cat.flip(flip, lump).transact() # then assert flipper.kicks() == kicks + 1 assert d.cat.flips(flip.id).tab == Wad(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)
def main(): if not w3.isConnected(): raise Exception("RPC not connected") print(f'Current block {w3.eth.blockNumber}') flipper = Flipper(web3=w3, address=Address(FLIPPER_CONTRACT)) current_block = w3.eth.blockNumber # Fetch logs logs: List[LogNote] = [] block = START_BLOCK block_batch = 5000 while block < END_BLOCK: print(f"Fetch logs from block {block} to {block + block_batch}") new_logs = flipper.past_logs_block_range( block, min(block + block_batch, current_block)) logs += new_logs block += block_batch print(f"Found {len(new_logs)} logs") auctions: dict() = {} # Process logs for log in logs: if isinstance(log, Flipper.KickLog): auctions[str(log.id)] = [log] elif isinstance(log, Flipper.TendLog) or isinstance( log, Flipper.DentLog) or isinstance(log, Flipper.DealLog): if str(log.id) in auctions: auctions[str(log.id)].append(log) else: raise Exception("Unknown event") print(f"Found {len(logs)} logs for {len(auctions)} auctions") print("==================================") # Print details for each auction for id, auction in auctions.items(): print_auction_details(auction, current_block)
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.other_address_1 = Address(self.web3.eth.accounts[1]) self.other_address_2 = Address(self.web3.eth.accounts[2]) self.dai = DSToken.deploy(self.web3, 'DAI') # we need a GemLike version of DSToken with push(bytes32, uint function) self.gem_addr = Contract._deploy(self.web3, Contract._load_abi(__name__, 'abi/GemMock.abi'), Contract._load_bin(__name__, 'abi/GemMock.bin'), [b'ABC']) self.gem = DSToken(web3=self.web3, address=self.gem_addr) self.flipper = Flipper.deploy(self.web3, self.dai.address, self.gem.address) # Set allowance to allow flipper to move dai and gem # With full deployment kick is only done by Cat via flip() which take care of allowance via gem.hope() self.gem.approve(self.flipper.address).transact() self.gem.approve(self.flipper.address).transact(from_address=self.other_address_1) self.dai.approve(self.flipper.address).transact()
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(flipper: Flipper): current_block = flipper.web3.eth.blockNumber return flipper.past_logs(current_block - 1, current_block)[0]
def __init__(self, flipper: Flipper): assert isinstance(flipper, Flipper) self.flipper = flipper self.beg = flipper.beg()