def __init__(self): super().__init__() self.base_token = ERC20Token(web3=self.web3, address=ERC20Token.token_address_by_name( self.arguments.base_token)) self.min_profit = Wad.from_number(self.arguments.min_profit) self.max_engagement = Wad.from_number(self.arguments.max_engagement) if len(self.arguments.excluded_makers) > 0: self.excluded_makers = set( map(lambda maker: Address(maker), self.arguments.excluded_makers.split(','))) else: self.excluded_makers = set() self.max_errors = self.arguments.max_errors self.errors = 0 if self.arguments.tx_manager: self.tx_manager_address = Address(self.arguments.tx_manager) self.tx_manager = TxManager(web3=self.web3, address=self.tx_manager_address) if self.tx_manager.owner() != self.our_address: logging.info( f"The TxManager has to be owned by the address the keeper is operating from." ) exit(-1) else: self.tx_manager_address = None self.tx_manager = None
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.our_address = Address(self.web3.eth.defaultAccount) self.second_address = Address(self.web3.eth.accounts[1]) self.token = DSToken.deploy(self.web3, 'ABC') self.token.mint(Wad(1000000))
def get_offer(self, offer_id: int) -> Optional[OfferInfo]: """Get the offer details. Args: offer_id: The id of the offer to get the details of. Returns: An instance of `OfferInfo` if the offer is still active, or `None` if the offer has been already completely taken. """ # if an offer is None, it won't become not-None again for the same OTC instance if offer_id in self._none_offers: return None array = self._contract.call().offers(offer_id) if array[5] is not True: self._none_offers.add(offer_id) return None else: return OfferInfo(offer_id=offer_id, sell_how_much=Wad(array[0]), sell_which_token=Address(array[1]), buy_how_much=Wad(array[2]), buy_which_token=Address(array[3]), owner=Address(array[4]), timestamp=array[6])
def __init__(self, args): self.token_get = Address(args['tokenGet']) self.amount_get = Wad(args['amountGet']) self.token_give = Address(args['tokenGive']) self.amount_give = Wad(args['amountGive']) self.expires = args['expires'] self.nonce = args['nonce'] self.user = Address(args['user'])
def __init__(self, args): self.id = bytes_to_int(args['id']) self.maker = Address(args['maker']) self.have_token = Address(args['haveToken']) self.have_amount = Wad(args['haveAmount']) self.want_token = Address(args['wantToken']) self.want_amount = Wad(args['wantAmount']) self.timestamp = args['timestamp']
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.our_address = Address(self.web3.eth.defaultAccount) self.other_address = Address(self.web3.eth.accounts[1]) self.tx = TxManager.deploy(self.web3) self.token1 = DSToken.deploy(self.web3, 'ABC') self.token1.mint(Wad.from_number(1000000)) self.token2 = DSToken.deploy(self.web3, 'DEF')
def test_give(self, sai: SaiDeployment): # given sai.tub.open() # when sai.tub.give(1, Address('0x0101010101020202020203030303030404040404')) # then assert sai.tub.lad(1) == Address( '0x0101010101020202020203030303030404040404')
def from_json(data: dict): assert (isinstance(data, dict)) return OffChainOrder(token_get=Address(data['tokenGet']), amount_get=Wad(int(data['amountGet'])), token_give=Address(data['tokenGive']), amount_give=Wad(int(data['amountGive'])), expires=int(data['expires']), nonce=int(data['nonce']), v=int(data['v']), r=hexstring_to_bytes(data['r']), s=hexstring_to_bytes(data['s']), user=Address(data['user']))
def __init__(self, auction_manager, auction_id, auction_info): self._auction_manager = auction_manager self.auction_id = auction_id self.creator = Address(auction_info[0]) self.selling = ERC20Token(web3=auction_manager.web3, address=Address(auction_info[1])) self.buying = ERC20Token(web3=auction_manager.web3, address=Address(auction_info[2])) self.start_bid = Wad(auction_info[3]) self.min_increase = auction_info[4] self.min_decrease = auction_info[5] self.sell_amount = Wad(auction_info[6]) self.ttl = auction_info[7] self.reversed = auction_info[8] self.unsold = auction_info[9]
def __init__(self): logging_format = '%(asctime)-15s %(levelname)-8s %(name)-6s %(message)s' logging.basicConfig(format=logging_format, level=logging.INFO) parser = argparse.ArgumentParser( description=f"{type(self).__name__} keeper") parser.add_argument("--rpc-host", help="JSON-RPC host (default: `localhost')", default="localhost", type=str) parser.add_argument("--rpc-port", help="JSON-RPC port (default: `8545')", default=8545, type=int) parser.add_argument( "--eth-from", help="Ethereum account from which to send transactions", required=True, type=str) self.args(parser) self.arguments = parser.parse_args() self.web3 = Web3( HTTPProvider( endpoint_uri= f"http://{self.arguments.rpc_host}:{self.arguments.rpc_port}")) self.web3.eth.defaultAccount = self.arguments.eth_from #TODO allow to use ETH_FROM env variable self.our_address = Address(self.arguments.eth_from) self.config = Config(self.chain()) self.terminated = False self._last_block_time = None
def fee_account(self) -> Address: """Returns the address of the fee account i.e. the account that receives all fees collected. Returns: The address of the fee account. """ return Address(self._contract.call().feeAccount())
def admin(self) -> Address: """Returns the address of the admin account. Returns: The address of the admin account. """ return Address(self._contract.call().admin())
def __init__(self): super().__init__() self.offchain = self.arguments.offchain self.order_age = self.arguments.order_age self.max_eth_amount = Wad.from_number(self.arguments.max_eth_amount) self.min_eth_amount = Wad.from_number(self.arguments.min_eth_amount) self.max_sai_amount = Wad.from_number(self.arguments.max_sai_amount) self.min_sai_amount = Wad.from_number(self.arguments.min_sai_amount) self.eth_reserve = Wad.from_number(self.arguments.eth_reserve) self.min_margin = self.arguments.min_margin self.avg_margin = self.arguments.avg_margin self.max_margin = self.arguments.max_margin self.etherdelta_address = Address( self.config.get_config()["etherDelta"]["contract"]) self.etherdelta_api_server = self.config.get_config()["etherDelta"]["apiServer"][1] \ if "apiServer" in self.config.get_config()["etherDelta"] \ else None self.etherdelta = EtherDelta(web3=self.web3, address=self.etherdelta_address, api_server=self.etherdelta_api_server) if self.offchain and not self.etherdelta.supports_offchain_orders(): raise Exception( "Off-chain EtherDelta orders not supported on this chain")
def from_dict(dict): from api import EventRole, Address user = User() user.id = dict["Id"] user.username = dict["Username"] user.forename = dict["Forename"] user.surname = dict["Surname"] user.email_address = dict["EmailAddress"] user.dob = dict["DOB"] address_dict = { "Id": dict["AddressId"], "Address1": dict["Address1"], "Address2": dict["Address2"], "Address3": dict["Address3"], "County": dict["County"], "Postcode": dict["Postcode"], "RowStatus": 0 } user.address = Address.from_dict(address_dict) role_dict = { "Id": dict["PrimaryEventRoleId"], "Name": dict["PrimaryEventRoleName"], "Description": dict["PrimaryEventRoleDescription"], "RowStatus": 0 } user.primary_event_role = EventRole.from_dict(role_dict) return user
def lps(self) -> Address: """Get the LPS token (liquidity provider shares). Returns: The address of the LPS token. """ return Address(self._contract.call().lps())
def ref(self) -> Address: """Get the ref token. Returns: The address of the ref token. """ return Address(self._contract.call().ref())
def tip(self) -> Address: """Get the target price engine. Returns: The address of the target price engine. It is an internal component of Sai. """ return Address(self._contract.call().tip())
def alt(self) -> Address: """Get the alt token. Returns: The address of the alt token. """ return Address(self._contract.call().alt())
def gem(self) -> Address: """Get the collateral token (eg. W-ETH). Returns: The address of the collateral token. """ return Address(self._contractTub.call().gem())
def pip(self) -> Address: """Get the GEM price feed. Returns: The address of the GEM price feed, which could be a `DSValue`, a `DSCache`, a `Mednianizer` etc. """ return Address(self._contractJar.call().pip())
def pot(self) -> Address: """Get the good debt vault. Returns: The address of the `DSVault` holding the good debt. """ return Address(self._contractTub.call().pot())
def skr(self) -> Address: """Get the SKR token. Returns: The address of the SKR token. """ return Address(self._contractTub.call().skr())
def pit(self) -> Address: """Get the liquidator vault. Returns: The address of the `DSVault` holding the bad debt. """ return Address(self._contractTub.call().pit())
def jar(self) -> Address: """Get the collateral vault. Returns: The address of the `SaiJar` vault. It is an internal component of Sai. """ return Address(self._contractTub.call().jar())
def jug(self) -> Address: """Get the SAI/SIN tracker. Returns: The address of the SAI/SIN tracker token. """ return Address(self._contractTub.call().jug())
def __init__(self): super().__init__() self.tub_address = Address(self.config.get_contract_address("saiTub")) self.tub = Tub(web3=self.web3, address=self.tub_address) self.tap_address = Address(self.config.get_contract_address("saiTap")) self.tap = Tap(web3=self.web3, address=self.tap_address) self.top_address = Address(self.config.get_contract_address("saiTop")) self.top = Top(web3=self.web3, address=self.top_address) self.otc_address = Address(self.config.get_contract_address("otc")) self.otc = SimpleMarket(web3=self.web3, address=self.otc_address) self.skr = ERC20Token(web3=self.web3, address=self.tub.skr()) self.sai = ERC20Token(web3=self.web3, address=self.tub.sai()) self.gem = DSEthToken(web3=self.web3, address=self.tub.gem()) ERC20Token.register_token(self.tub.skr(), 'SKR') ERC20Token.register_token(self.tub.sai(), 'SAI') ERC20Token.register_token(self.tub.gem(), 'WETH')
def new_sai() -> SaiDeployment: def deploy(web3, contract_name, args=None): contract_factory = web3.eth.contract( abi=json.loads( pkg_resources.resource_string('api.feed', f'abi/{contract_name}.abi')), bytecode=pkg_resources.resource_string('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) for auth in [sai, sin, skr, pot, pit, tub, tap, top]: auth.set_authority(dad.address) # approve, mint some GEMs tub.approve(directly()) gem.mint(Wad.from_number(1000000)) web3.currentProvider.rpc_methods.evm_snapshot() return SaiDeployment(web3, our_address, gem, sai, skr, tub, tap, top)
def pip(self) -> Address: """Get the price feed (giving refs per alt). You can get the current feed value by calling `tag()`. Returns: The address of the price feed, which could be a `DSValue`, a `DSCache`, a `Mednianizer` etc. """ return Address(self._contract.call().pip())
def test_shut(self, sai: SaiDeployment): # given sai.tub.open() # when sai.tub.shut(1) # then assert sai.tub.lad(1) == Address( '0x0000000000000000000000000000000000000000')
def test_token_registry(self): # given ERC20Token.register_token(Address('0x0100000000000000000000000000000000000000'), 'ABC') ERC20Token.register_token(Address('0x0200000000000000000000000000000000000000'), 'DEF') ERC20Token.register_token(Address('0x0300000000000000000000000000000000000000'), 'GHI') # expect assert ERC20Token.token_name_by_address(Address('0x0100000000000000000000000000000000000000')) == 'ABC' assert ERC20Token.token_name_by_address(Address('0x0200000000000000000000000000000000000000')) == 'DEF' assert ERC20Token.token_name_by_address(Address('0x0300000000000000000000000000000000000000')) == 'GHI' with pytest.raises(Exception): assert ERC20Token.token_name_by_address(Address('0x0400000000000000000000000000000000000000')) # and assert ERC20Token.token_address_by_name('ABC') == Address('0x0100000000000000000000000000000000000000') assert ERC20Token.token_address_by_name('DEF') == Address('0x0200000000000000000000000000000000000000') assert ERC20Token.token_address_by_name('GHI') == Address('0x0300000000000000000000000000000000000000') with pytest.raises(Exception): ERC20Token.token_address_by_name('XXX')