def test_fog_and_woe_and_bust(self, sai: SaiDeployment): # given sai.tub.join(Wad.from_number(10)).transact() sai.tub.cork(Wad.from_number(100000)).transact() DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() # and sai.tub.open().transact() sai.tub.lock(1, Wad.from_number(4)).transact() sai.tub.draw(1, Wad.from_number(1000)).transact() # and DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(150).value).transact() # when sai.tub.bite(1).transact() # then assert sai.tap.fog() == Wad.from_number(4) assert sai.tap.woe() == Wad.from_number(1000) assert sai.skr.balance_of(sai.our_address) == Wad.from_number(6) assert sai.sai.balance_of(sai.our_address) == Wad.from_number(1000) # when sai.tap.bust(Wad.from_number(2)).transact() assert sai.tap.fog() == Wad.from_number(2) assert sai.tap.woe() == Wad.from_number(700) assert sai.skr.balance_of(sai.our_address) == Wad.from_number(8) assert sai.sai.balance_of(sai.our_address) == Wad.from_number(700)
def test_bite_and_safe(self, sai: SaiDeployment): # given sai.tub.join(Wad.from_number(10)).transact() sai.tub.cork(Wad.from_number(100000)).transact() DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() # when sai.tub.open().transact() sai.tub.lock(1, Wad.from_number(4)).transact() sai.tub.draw(1, Wad.from_number(1000)).transact() # then assert sai.tub.safe(1) # when DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(150).value).transact() # then assert not sai.tub.safe(1) # when sai.tub.bite(1).transact() # then assert sai.tub.safe(1)
def test_joy_and_boom(self, sai: SaiDeployment): # given sai.tub.join(Wad.from_number(10)).transact() sai.tub.cork(Wad.from_number(100000)).transact() sai.tub.crop(Ray(1000100000000000000000000000)).transact() DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() # and sai.tub.open().transact() sai.tub.lock(1, Wad.from_number(4)).transact() sai.tub.draw(1, Wad.from_number(1000)).transact() # when sai.tub.drip().transact() sai.tub.warp(3600).transact() sai.tub.drip().transact() # then assert sai.skr.balance_of(sai.our_address) == Wad.from_number(6) assert sai.tap.joy() == Wad(433303616582911495481) # when sai.tap.boom(Wad.from_number(1)).transact() # then assert sai.skr.balance_of(sai.our_address) == Wad.from_number(5) assert sai.tap.joy() == Wad(183303616582911495481)
def test_draw_and_tab_and_ice_and_wipe(self, sai: SaiDeployment): # given sai.tub.join(Wad.from_number(10)).transact() sai.tub.cork(Wad.from_number(100000)).transact() DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250.45).value).transact() # and sai.tub.open().transact() sai.tub.lock(1, Wad.from_number(5)).transact() # when sai.tub.draw(1, Wad.from_number(50)).transact() # then assert sai.sai.balance_of(sai.our_address) == Wad.from_number(50) assert sai.tub.tab(1) == Wad.from_number(50) assert sai.tub.ice() == Wad.from_number(50) # when sai.tub.wipe(1, Wad.from_number(30)).transact() # then assert sai.sai.balance_of(sai.our_address) == Wad.from_number(20) assert sai.tub.tab(1) == Wad.from_number(20) assert sai.tub.ice() == Wad.from_number(20)
def test_tag(self, sai: SaiDeployment): # when DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250.45).value).transact() # then assert sai.tub.tag() == Wad.from_number(250.45)
def test_should_create_offers_on_startup(self, sai: SaiDeployment): # given keeper = self.setup_keeper(sai) keeper.max_weth_amount = Wad.from_number(10) keeper.min_weth_amount = Wad.from_number(5) keeper.max_sai_amount = Wad.from_number(100) keeper.min_sai_amount = Wad.from_number(50) keeper.sai_dust_cutoff = Wad.from_number(0) keeper.weth_dust_cutoff = Wad.from_number(0) keeper.min_margin_buy = 0.01 keeper.avg_margin_buy = 0.02 keeper.max_margin_buy = 0.03 keeper.min_margin_sell = 0.02 keeper.avg_margin_sell = 0.03 keeper.max_margin_sell = 0.04 keeper.round_places = 2 keeper.gas_price = DefaultGasPrice() # and DSToken(web3=sai.web3, address=sai.tub.gem()).mint(Wad.from_number(1000)).transact() DSToken(web3=sai.web3, address=sai.tub.sai()).mint(Wad.from_number(1000)).transact() # and print(sai.tub.pip()) DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() # when keeper.approve() keeper.synchronize_offers() # then assert len(keeper.otc.active_offers()) == 2
def test_s2s_and_bid_and_ask(self, sai: SaiDeployment): # when DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(500).value).transact() sai.tap.jump(Wad.from_number(1.05)).transact() # then assert sai.tap.bid() == Wad.from_number(475) assert sai.tap.s2s() == Wad.from_number(500) assert sai.tap.ask() == Wad.from_number(525)
def test_shut(self, sai: SaiDeployment): # given DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() sai.tub.open().transact() # when sai.tub.shut(1).transact() # then assert sai.tub.lad(1) == Address( '0x0000000000000000000000000000000000000000')
def test_safe(self, sai: SaiDeployment): # given sai.tub.cuff(Ray.from_number(1.5)).transact() sai.tub.chop(Ray.from_number(1.2)).transact() DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() # when sai.tub.open().transact() # then assert sai.tub.safe(1)
def test_should_bite_unsafe_cups_only(self, sai: SaiDeployment): # given keeper = self.setup_keeper(sai) # and sai.tub.join(Wad.from_number(10)).transact() sai.tub.cork(Wad.from_number(100000)).transact() DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() # and sai.tub.open().transact() sai.tub.lock(1, Wad.from_number(4)).transact() sai.tub.draw(1, Wad.from_number(1000)).transact() # and assert sai.tub.safe(1) # when keeper.check_all_cups() # then assert sai.tub.safe(1) assert sai.tub.tab(1) == Wad.from_number(1000) # when DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(150).value).transact() # and assert not sai.tub.safe(1) # and keeper.check_all_cups() # then assert sai.tub.safe(1) assert sai.tub.tab(1) == Wad.from_number(0)
def new_sai() -> SaiDeployment: def deploy(web3, contract_name, args=None): contract_factory = web3.eth.contract( abi=json.loads( pkg_resources.resource_string('keeper.api.feed', f'abi/{contract_name}.abi')), bytecode=pkg_resources.resource_string('keeper.api.feed', f'abi/{contract_name}.bin')) tx_hash = contract_factory.deploy(args=args) receipt = web3.eth.getTransactionReceipt(tx_hash) return receipt['contractAddress'] web3 = Web3(EthereumTesterProvider()) web3.eth.defaultAccount = web3.eth.accounts[0] our_address = Address(web3.eth.defaultAccount) sai = DSToken.deploy(web3, 'SAI') sin = DSToken.deploy(web3, 'SIN') gem = DSToken.deploy(web3, 'ETH') pip = DSValue.deploy(web3) skr = DSToken.deploy(web3, 'SKR') pot = DSVault.deploy(web3) pit = DSVault.deploy(web3) tip = deploy(web3, 'Tip') dad = DSGuard.deploy(web3) jug = deploy(web3, 'SaiJug', [sai.address.address, sin.address.address]) jar = deploy( web3, 'SaiJar', [skr.address.address, gem.address.address, pip.address.address]) tub = Tub.deploy(web3, Address(jar), Address(jug), pot.address, pit.address, Address(tip)) tap = Tap.deploy(web3, tub.address, pit.address) top = Top.deploy(web3, tub.address, tap.address) # set permissions dad.permit(DSGuard.ANY, DSGuard.ANY, DSGuard.ANY).transact() tub.set_authority(dad.address) for auth in [sai, sin, skr, pot, pit, tap, top]: auth.set_authority(dad.address).transact() # approve, mint some GEMs tub.approve(directly()) gem.mint(Wad.from_number(1000000)).transact() web3.currentProvider.rpc_methods.evm_snapshot() return SaiDeployment(web3, our_address, gem, sai, sin, skr, tub, tap, top)
def tub_target_price(self) -> Wad: """SAI per GEM price that we are targeting.""" try: cmdstr = "setzer price gemini" process = subprocess.Popen(cmdstr.split(), stdout=subprocess.PIPE) output, error = process.communicate() if error != None: raise ValueError('Error reading feed!') feed_price = float(output) ref_per_gem = Wad.from_number(feed_price) self.logger.debug( f"Successfully read Gemini feed, target price set to: {feed_price}" ) except: self.logger.info( f"Exception reading Gemini feed, falling back to tub.pip().") ref_per_gem = Wad( DSValue(web3=self.web3, address=self.tub.pip()).read_as_int()) return ref_per_gem / self.tub.par()
def test_lock_and_free(self, sai: SaiDeployment): # given DSValue(web3=sai.web3, address=sai.tub.pip()).poke_with_int( Wad.from_number(250).value).transact() sai.tub.open().transact() sai.tub.join(Wad.from_number(10)).transact() # when print(sai.tub.cupi()) sai.tub.lock(1, Wad.from_number(5)).transact() # then assert sai.tub.ink(1) == Wad.from_number(5) assert sai.tub.air() == Wad.from_number(5) # when sai.tub.free(1, Wad.from_number(3)).transact() # then assert sai.tub.ink(1) == Wad.from_number(2) assert sai.tub.air() == Wad.from_number(2)
def target_rate(self) -> Wad: ref_per_gem = Wad( DSValue(web3=self.web3, address=self.tub.pip()).read_as_int()) return self.tub.par() / ref_per_gem
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.dsvalue = DSValue.deploy(self.web3)
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.dsvalue = DSValue.deploy(self.web3)