from pyflex.deployment import GfDeployment from pyflex.keys import register_keys from pyflex.numeric import Wad from pyflex.proxy import DSProxy endpoint_uri = f"{os.environ['SERVER_ETH_RPC_HOST']}:{os.environ['SERVER_ETH_RPC_PORT']}" web3 = Web3( HTTPProvider(endpoint_uri=endpoint_uri, request_kwargs={"timeout": 10})) web3.eth.defaultAccount = sys.argv[ 1] # ex: 0x0000000000000000000000000000000aBcdef123 register_keys( web3, [sys.argv[2]] ) # ex: key_file=~keys/default-account.json,pass_file=~keys/default-account.pass safeid = int(sys.argv[3]) geb = GfDeployment.from_network(web3, "kovan") our_address = Address(web3.eth.defaultAccount) proxy = geb.proxy_registry.proxies(our_address) if proxy == Address("0x0000000000000000000000000000000000000000"): print(f"No proxy exists for our address. Building one first") geb.proxy_registry.build(our_address).transact() proxy = DSProxy(web3, Address(geb.proxy_registry.proxies(our_address))) print(f"Default account: {our_address.address}") print( f"{our_address} has a DS-Proxy - {proxy.address.address}, test will continue" ) print(f"SAFE of Safe ID {safeid} - {geb.safe_manager.safe(safeid)}")
def __init__(self, args: list, **kwargs): """Pass in arguements assign necessary variables/objects and instantiate other Classes""" parser = argparse.ArgumentParser("settlement-keeper") parser.add_argument( "--rpc-uri", type=str, default="http://localhost:8545", help="JSON-RPC host (default: `http://localhost:8545')") parser.add_argument("--rpc-timeout", type=int, default=1200, help="JSON-RPC timeout (in seconds, default: 10)") parser.add_argument( "--network", type=str, required=True, help= "Network that you're running the Keeper on (options, 'mainnet', 'kovan', 'testnet')" ) parser.add_argument( '--previous-settlement', dest='settlement_facilitated', action='store_true', help= 'Include this argument if this keeper previously helped to facilitate the processing phase of ES' ) parser.add_argument( "--graph-endpoint", type=str, default=None, help= "When specified, safe history will be initialized from a Graph node, " "reducing load on the Ethereum node for collateral auctions") parser.add_argument( "--eth-from", type=str, required=True, help= "Ethereum address from which to send transactions; checksummed (e.g. '0x12AebC')" ) parser.add_argument( "--eth-key", type=str, nargs='*', help= "Ethereum private key(s) to use (e.g. 'key_file=/path/to/keystore.json,pass_file=/path/to/passphrase.txt')" ) parser.add_argument( "--gf-deployment-file", type=str, required=False, help= "Json description of all the system addresses (e.g. /Full/Path/To/configFile.json)" ) parser.add_argument( "--safe-engine-deployment-block", type=int, required=False, default=0, help= "Block that the SAFEEngine from gf-deployment-file was deployed at (e.g. 8836668" ) parser.add_argument( "--max-errors", type=int, default=100, help= "Maximum number of allowed errors before the keeper terminates (default: 100)" ) parser.add_argument("--debug", dest='debug', action='store_true', help="Enable debug output") parser.add_argument("--ethgasstation-api-key", type=str, default=None, required=False, help="ethgasstation API key") parser.add_argument("--gas-initial-multiplier", type=str, default=1.0, help="gas strategy tuning") parser.add_argument("--gas-reactive-multiplier", type=str, default=2.25, help="gas strategy tuning") parser.add_argument("--gas-maximum", type=str, default=5000, help="gas strategy tuning") parser.set_defaults(settlement_facilitated=False) self.arguments = parser.parse_args(args) self.web3 = kwargs['web3'] if 'web3' in kwargs else \ Web3(HTTPProvider(endpoint_uri=self.arguments.rpc_uri, request_kwargs={"timeout": self.arguments.rpc_timeout})) self.web3.eth.defaultAccount = self.arguments.eth_from register_keys(self.web3, self.arguments.eth_key) self.our_address = Address(self.arguments.eth_from) if self.arguments.gf_deployment_file: self.geb = GfDeployment.from_json( web3=self.web3, conf=open(self.arguments.gf_deployment_file, "r").read()) else: self.geb = GfDeployment.from_network( web3=self.web3, network=self.arguments.network) self.deployment_block = self.arguments.safe_engine_deployment_block self.max_errors = self.arguments.max_errors self.errors = 0 self.settlement_facilitated = self.arguments.settlement_facilitated self.confirmations = 0 # Create gas strategy if self.arguments.ethgasstation_api_key: self.gas_price = DynamicGasPrice(self.arguments, self.web3) else: self.gas_price = DefaultGasPrice() logging.basicConfig( format='%(asctime)-15s %(levelname)-8s %(message)s', level=(logging.DEBUG if self.arguments.debug else logging.INFO))
def geb(web3) -> GfDeployment: deployment = GfDeployment.from_network(web3=web3, network="testnet") validate_contracts_loaded(deployment) return deployment