Пример #1
0
def get_web3():
    # These details are specific to the GEB testchain used for pyflex unit tests.
    web3 = web3_via_http("http://0.0.0.0:8545", 3, 100)
    web3.eth.defaultAccount = "0x50FF810797f75f6bfbf2227442e0c961a8562F4C"
    register_keys(web3, [
        "key_file=lib/pyflex/tests/config/keys/UnlimitedChain/key1.json,pass_file=/dev/null",
        "key_file=lib/pyflex/tests/config/keys/UnlimitedChain/key2.json,pass_file=/dev/null",
        "key_file=lib/pyflex/tests/config/keys/UnlimitedChain/key3.json,pass_file=/dev/null",
        "key_file=lib/pyflex/tests/config/keys/UnlimitedChain/key4.json,pass_file=/dev/null",
        "key_file=lib/pyflex/tests/config/keys/UnlimitedChain/key.json,pass_file=/dev/null"
    ])

    # reduce logspew
    logging.getLogger("web3").setLevel(logging.INFO)
    logging.getLogger("urllib3").setLevel(logging.INFO)
    logging.getLogger("asyncio").setLevel(logging.INFO)

    return web3
Пример #2
0
def web3() -> Web3:
    # for local dockerized parity testchain
    web3 = Web3(HTTPProvider("http://0.0.0.0:8545"))
    web3.eth.defaultAccount = "0x50FF810797f75f6bfbf2227442e0c961a8562F4C"
    register_keys(web3, [
        "key_file=tests/config/keys/UnlimitedChain/key1.json,pass_file=/dev/null",
        "key_file=tests/config/keys/UnlimitedChain/key2.json,pass_file=/dev/null",
        "key_file=tests/config/keys/UnlimitedChain/key3.json,pass_file=/dev/null",
        "key_file=tests/config/keys/UnlimitedChain/key4.json,pass_file=/dev/null",
        "key_file=tests/config/keys/UnlimitedChain/key.json,pass_file=/dev/null"
    ])

    # reduce logspew
    logging.getLogger("web3").setLevel(logging.INFO)
    logging.getLogger("urllib3").setLevel(logging.INFO)
    logging.getLogger("asyncio").setLevel(logging.INFO)

    assert len(web3.eth.accounts) > 3
    return web3
Пример #3
0
pyflex_warning()

new_collateral_amount = Wad.from_number(sys.argv[1])
new_debt_amount = Wad.from_number(sys.argv[2])

ETH_RPC_URL = os.environ['ETH_RPC_URL']

web3 = Web3(
    HTTPProvider(endpoint_uri=ETH_RPC_URL, request_kwargs={"timeout": 60}))
while web3.eth.syncing:
    print("Node is syncing")
    time.sleep(5)

print(f"Current block number: {web3.eth.blockNumber}")
web3.eth.defaultAccount = os.environ['ETH_ACCOUNT']
register_keys(web3, [os.environ['ETH_KEYPASS']])

geb = GfDeployment.from_node(web3, 'rai')
our_address = Address(web3.eth.defaultAccount)

collateral = geb.collaterals['ETH-A']
collateral_type = geb.safe_engine.collateral_type(
    collateral.collateral_type.name)

# Get SAFE status before modification
safe = geb.safe_engine.safe(collateral_type, our_address)
if safe.generated_debt > Wad(0):
    coll_ratio = (safe.locked_collateral * collateral_type.liquidation_price *
                  geb.oracle_relayer.liquidation_c_ratio(collateral_type)) / (
                      safe.generated_debt *
                      collateral_type.accumulated_rate) * 100
Пример #4
0
logging.basicConfig(format='%(asctime)-15s %(levelname)-8s %(message)s',
                    level=logging.DEBUG)
# reduce logspew
logging.getLogger('urllib3').setLevel(logging.INFO)
logging.getLogger("web3").setLevel(logging.INFO)
logging.getLogger("asyncio").setLevel(logging.INFO)

pool_size = int(sys.argv[3]) if len(sys.argv) > 3 else 10

#web3 = Web3(HTTPProvider(endpoint_uri=os.environ['ETH_RPC_URL'], request_kwargs={"timeout": 60}))
web3 = web3_via_http(endpoint_uri=os.environ['ETH_RPC_URL'],
                     http_pool_size=pool_size)
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

geb = GfDeployment.from_node(web3, 'rai')
our_address = Address(web3.eth.defaultAccount)

weth = geb.collaterals['ETH-A'].collateral

GWEI = 1000000000
slow_gas = GeometricGasPrice(initial_price=int(15 * GWEI),
                             every_secs=42,
                             max_price=300 * GWEI)
fast_gas = GeometricGasPrice(initial_price=int(90 * GWEI),
                             every_secs=42,
                             max_price=300 * GWEI)
Пример #5
0
    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))