Beispiel #1
0
    def setup_method(self):
        py_evm_main.GENESIS_GAS_LIMIT = 10000000
        #self.web3 = Web3(EthereumTesterProvider(EthereumTester(PyEVMBackend())))
        self.web3 = Web3(HTTPProvider("http://0.0.0.0:8555"))
        self.web3.eth.defaultAccount = self.web3.eth.accounts[0]
        self.our_address = Address(self.web3.eth.defaultAccount)

        self.zrx_token = ERC20Token(web3=self.web3,
                                    address=deploy_contract(
                                        self.web3, 'ZRXToken'))
        self.token_transfer_proxy_address = deploy_contract(
            self.web3, 'TokenTransferProxy')
        self.exchange = ZrxExchange.deploy(self.web3, self.zrx_token.address,
                                           self.token_transfer_proxy_address)
        self.web3.eth.contract(abi=json.loads(
            pkg_resources.resource_string(
                'pyflex.deployment', f'abi/TokenTransferProxy.abi')))(
                    address=self.token_transfer_proxy_address.address
                ).functions.addAuthorizedAddress(
                    self.exchange.address.address).transact()

        self.zrx_api = ZrxApi(self.exchange)

        self.dgx = DSToken.deploy(self.web3, 'DGX', 'DGX')
        self.dai = DSToken.deploy(self.web3, 'DAI', 'DAI')
        self.pair = Pair(self.dgx.address, 9, self.dai.address, 18)
Beispiel #2
0
    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.zrx_token = ERC20Token(web3=self.web3,
                                    address=deploy_contract(
                                        self.web3, 'ZRXToken'))

        self.asset_proxy = deploy_contract(self.web3, 'ExchangeV2-ERC20Proxy')
        self.exchange = ZrxExchangeV2.deploy(
            self.web3,
            None)  #"0xf47261b0" + self.zrx_token.address.address - unused yet
        self.exchange._contract.functions.registerAssetProxy(
            self.asset_proxy.address).transact()

        token_proxy_abi = json.loads(
            pkg_resources.resource_string('pyflex.deployment',
                                          f'abi/ExchangeV2-ERC20Proxy.abi'))
        asset_proxy_contract = self.web3.eth.contract(abi=token_proxy_abi)(
            address=self.asset_proxy.address)
        asset_proxy_contract.functions.addAuthorizedAddress(
            self.exchange.address.address).transact()

        self.token1 = DSToken.deploy(self.web3, 'AAA', 'AAA')
        self.token1.mint(Wad.from_number(100)).transact()
        self.token2 = DSToken.deploy(self.web3, 'BBB', 'BBB')
        self.token2.mint(Wad.from_number(100)).transact()
Beispiel #3
0
 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 = Address(self.web3.eth.accounts[1])
     self.tx = TxManager.deploy(self.web3)
     self.token1 = DSToken.deploy(self.web3, 'ABC', 'ABC')
     self.token1.mint(Wad.from_number(1000000)).transact()
     self.token2 = DSToken.deploy(self.web3, 'DEF', 'DEF')
     self.token2.mint(Wad.from_number(1000000)).transact()
Beispiel #4
0
    def test_equals(self):
        # given
        token1 = DSToken.deploy(self.web3, 'ABC', 'ABC')
        token2 = DSToken.deploy(self.web3, 'DEF', 'DEF')
        token2b = ERC20Token(web3=self.web3, address=token2.address)

        # expect
        assert token1 == token1
        assert token2 == token2b
        assert not token1 == token2
        assert not token1 == token2b
Beispiel #5
0
def mint_prot(prot: DSToken, recipient_address: Address, amount: Wad):
    assert isinstance(prot, DSToken)
    assert isinstance(recipient_address, Address)
    assert isinstance(amount, Wad)
    assert amount > Wad(0)

    deployment_address = Address("0x00a329c0648769A73afAc7F9381E08FB43dBEA72")
    assert prot.mint(amount).transact(from_address=deployment_address)
    assert prot.balance_of(deployment_address) > Wad(0)
    assert prot.approve(recipient_address).transact(
        from_address=deployment_address)
    assert prot.transfer(recipient_address,
                         amount).transact(from_address=deployment_address)
Beispiel #6
0
def test_local_accounts_register_key():
    # given
    # [that address is not recognized by ganache, this way we can be sure it's the local account being used for signing]
    web3 = Web3(HTTPProvider("http://localhost:8555"))
    web3.eth.defaultAccount = Address(
        '0x13314e21cd6d343ceb857073f3f6d9368919d1ef').address

    # and
    keyfile_path = pkg_resources.resource_filename(
        __name__, "accounts/4_0x13314e21cd6d343ceb857073f3f6d9368919d1ef.json")
    passfile_path = pkg_resources.resource_filename(__name__, "accounts/pass")
    register_key(web3, f"key_file={keyfile_path},pass_file={passfile_path}")

    # and
    # [as ganache does not know this address, we need to send some ETH to it first]
    eth_transfer(web3, Address(web3.eth.defaultAccount), Wad.from_number(100)) \
        .transact(from_address=Address(web3.eth.accounts[0]))

    # when
    # [we deploy some test contract and mint some tokens]
    token = DSToken.deploy(web3, 'XYZ', 'XYZ')
    token.mint(Wad.from_number(150000)).transact()

    # then
    # [these operations were successful]
    assert token.balance_of(Address(
        web3.eth.defaultAccount)) == Wad.from_number(150000)
Beispiel #7
0
 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.second_address = Address(self.web3.eth.accounts[1])
     self.third_address = Address(self.web3.eth.accounts[2])
     self.token = DSToken.deploy(self.web3, 'ABC', 'ABC')
     self.token.mint(Wad(1000000)).transact()
    def setup_method(self):

        # Use Ganache docker container
        self.web3 = Web3(HTTPProvider("http://0.0.0.0:8555"))
        self.web3.eth.defaultAccount = Web3.toChecksumAddress(
            "0x9596C16D7bF9323265C2F2E22f43e6c80eB3d943")
        register_private_key(
            self.web3,
            "0x91cf2cc3671a365fcbf38010ff97ee31a5b7e674842663c56769e41600696ead"
        )

        self.our_address = Address(self.web3.eth.defaultAccount)

        self.weth_address = self._deploy(self.web3, self.weth_abi,
                                         self.weth_bin, [])
        self.factory_address = self._deploy(self.web3, self.factory_abi,
                                            self.factory_bin,
                                            [self.our_address.address])
        self.router_address = self._deploy(
            self.web3, self.router_abi, self.router_bin,
            [self.factory_address.address, self.weth_address.address])
        self._weth_contract = self._get_contract(self.web3, self.weth_abi,
                                                 self.weth_address)

        self.ds_systemcoin = DSToken.deploy(self.web3, 'SystemCoin', 'sys')
        self.ds_usdc = DSToken.deploy(self.web3, 'USDC', 'USDC')
        self.token_systemcoin = Token("SystemCoin", self.ds_systemcoin.address,
                                      18)
        self.token_usdc = Token("USDC", self.ds_usdc.address, 6)
        self.token_weth = Token("WETH", self.weth_address, 18)

        self.systemcoin_usdc_uniswap = UniswapV2(
            self.web3, self.token_systemcoin, self.token_usdc,
            self.our_address, self.router_address, self.factory_address)
        self.systemcoin_eth_uniswap = UniswapV2(
            self.web3, self.token_systemcoin, self.token_weth,
            self.our_address, self.router_address, self.factory_address)

        ## Useful for debugging failing transactions
        logger = logging.getLogger('eth')
        logger.setLevel(8)
Beispiel #9
0
 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.zrx_token = ERC20Token(web3=self.web3,
                                 address=deploy_contract(
                                     self.web3, 'ZRXToken'))
     self.token_transfer_proxy_address = deploy_contract(
         self.web3, 'TokenTransferProxy')
     self.exchange = ZrxExchange.deploy(self.web3, self.zrx_token.address,
                                        self.token_transfer_proxy_address)
     token_proxy_abi = json.loads(
         pkg_resources.resource_string('pyflex.deployment',
                                       f'abi/TokenTransferProxy.abi'))
     self.web3.eth.contract(abi=token_proxy_abi)\
         (address=self.token_transfer_proxy_address.address).functions.addAuthorizedAddress(
         self.exchange.address.address).transact()
     self.token1 = DSToken.deploy(self.web3, 'AAA', 'AAA')
     self.token1.mint(Wad.from_number(100)).transact()
     self.token2 = DSToken.deploy(self.web3, 'BBB', 'BBB')
     self.token2.mint(Wad.from_number(100)).transact()
Beispiel #10
0
def test_multiple_local_accounts():
    # given
    local_account_1 = Address('0x13314e21cd6d343ceb857073f3f6d9368919d1ef')
    local_account_2 = Address('0x176087fea5c41fc370fabbd850521bc4451690ca')

    # and
    # [that address is not recognized by ganache, this way we can be sure it's the local account being used for signing]
    web3 = Web3(HTTPProvider("http://localhost:8555"))
    web3.eth.defaultAccount = local_account_1.address

    # and
    keyfile_path = pkg_resources.resource_filename(
        __name__, "accounts/4_0x13314e21cd6d343ceb857073f3f6d9368919d1ef.json")
    passfile_path = pkg_resources.resource_filename(__name__, "accounts/pass")
    register_key_file(web3, keyfile_path, passfile_path)

    # and
    keyfile_path = pkg_resources.resource_filename(
        __name__, "accounts/5_0x176087fea5c41fc370fabbd850521bc4451690ca.json")
    passfile_path = pkg_resources.resource_filename(__name__, "accounts/pass")
    register_key_file(web3, keyfile_path, passfile_path)

    # and
    # [as ganache does not know these addresses, we need to send some ETH to it first]
    eth_transfer(web3, local_account_1, Wad.from_number(100)).transact(
        from_address=Address(web3.eth.accounts[0]))
    eth_transfer(web3, local_account_2, Wad.from_number(100)).transact(
        from_address=Address(web3.eth.accounts[0]))

    # when
    # [we execute some test scenario involving two addresses]
    token = DSToken.deploy(web3, 'XYZ', 'XYZ')
    token.mint(Wad.from_number(150000)).transact()
    token.transfer(local_account_2, Wad.from_number(60000)).transact()
    token.transfer(
        local_account_1,
        Wad.from_number(10000)).transact(from_address=local_account_2)

    # then
    # [these operations were successful]
    assert token.balance_of(local_account_1) == Wad.from_number(100000)
    assert token.balance_of(local_account_2) == Wad.from_number(50000)
Beispiel #11
0
        def from_json(web3: Web3, conf: str):
            conf = json.loads(conf)
            pause = DSPause(web3, Address(conf['GEB_PAUSE']))
            safe_engine = SAFEEngine(web3, Address(conf['GEB_SAFE_ENGINE']))
            accounting_engine = AccountingEngine(
                web3, Address(conf['GEB_ACCOUNTING_ENGINE']))
            tax_collector = TaxCollector(web3,
                                         Address(conf['GEB_TAX_COLLECTOR']))
            liquidation_engine = LiquidationEngine(
                web3, Address(conf['GEB_LIQUIDATION_ENGINE']))
            system_coin = DSToken(web3, Address(conf['GEB_COIN']))
            system_coin_adapter = CoinJoin(web3,
                                           Address(conf['GEB_COIN_JOIN']))
            surplus_auction_house = PreSettlementSurplusAuctionHouse(
                web3, Address(conf['GEB_SURPLUS_AUCTION_HOUSE']))
            debt_auction_house = DebtAuctionHouse(
                web3, Address(conf['GEB_DEBT_AUCTION_HOUSE']))
            coin_savings_acct = CoinSavingsAccount(web3,
                                                   Address(conf['GEB_COIN']))
            oracle_relayer = OracleRelayer(web3,
                                           Address(conf['GEB_ORACLE_RELAYER']))
            global_settlement = GlobalSettlement(
                web3, Address(conf['GEB_GLOBAL_SETTLEMENT']))
            proxy_registry = ProxyRegistry(web3,
                                           Address(conf['PROXY_REGISTRY']))
            proxy_actions = GebProxyActions(web3,
                                            Address(conf['PROXY_ACTIONS']))
            safe_manager = SafeManager(web3, Address(conf['SAFE_MANAGER']))
            mc_keeper_flash_proxy = GebMCKeeperFlashProxy(
                web3,
                Address(
                    conf['GEB_UNISWAP_MULTI_COLLATERAL_KEEPER_FLASH_PROXY']))
            starting_block_number = int(conf['STARTING_BLOCK_NUMBER'])

            # Kovan deployment current doesn't have PROT or ESM
            try:
                prot = DSToken(web3, Address(conf['GEB_PROT']))
            except:
                prot = None
            try:
                esm = ESM(web3, Address(conf['GEB_ESM']))
            except:
                esm = None

            try:
                uniswap_factory = Address(conf['UNISWAP_FACTORY'])
            except:
                uniswap_factory = None

            try:
                uniswap_router = Address(conf['UNISWAP_ROUTER'])
            except:
                uniswap_router = None

            collaterals = {}
            for name in GfDeployment.Config._infer_collaterals_from_addresses(
                    conf.keys()):
                collateral_type = CollateralType(name[0].replace('_', '-'))
                if name[1] == "ETH":
                    collateral = DSEthToken(web3, Address(conf[name[1]]))
                else:
                    collateral = DSToken(web3, Address(conf[name[1]]))

                # osm_address contract may be a DSValue, OSM, DSM, or bogus address.
                osm_address = Address(conf[f'FEED_SECURITY_MODULE_{name[1]}'])
                network = GfDeployment.NETWORKS.get(web3.net.version,
                                                    "testnet")

                osm = DSValue(web3,
                              osm_address) if network == "testnet" else OSM(
                                  web3, osm_address)

                adapter = BasicCollateralJoin(
                    web3, Address(conf[f'GEB_JOIN_{name[0]}']))

                # Detect which auction house is used
                try:
                    coll_auction_house = IncreasingDiscountCollateralAuctionHouse(
                        web3,
                        Address(
                            conf[f'GEB_COLLATERAL_AUCTION_HOUSE_{name[0]}']))
                except:
                    try:
                        coll_auction_house = EnglishCollateralAuctionHouse(
                            web3,
                            Address(
                                conf[f'GEB_COLLATERAL_AUCTION_HOUSE_{name[0]}']
                            ))
                    except:
                        raise ValueError(
                            f"Unknown auction house: GEB_COLLATERAL_AUCTION_HOUSE_{name[0]}"
                        )

                try:
                    flash_proxy = GebETHKeeperFlashProxy(
                        web3,
                        Address(conf[
                            f'GEB_UNISWAP_SINGLE_KEEPER_FLASH_PROXY_{name[0]}']
                                ))
                except Exception as e:
                    print(e)
                    flash_proxy = None

                try:
                    flash_proxy_dai_v3 = GebETHKeeperFlashProxy(
                        web3,
                        Address(conf[
                            f'GEB_UNISWAP_V3_MULTI_HOP_KEEPER_FLASH_PROXY_DAI_{name[0]}']
                                ))
                except Exception as e:
                    print(e)
                    flash_proxy_dai_v3 = None

                try:
                    flash_proxy_usdc_v3 = GebETHKeeperFlashProxy(
                        web3,
                        Address(conf[
                            f'GEB_UNISWAP_V3_MULTI_HOP_KEEPER_FLASH_PROXY_USDC_{name[0]}']
                                ))
                except Exception as e:
                    print(e)
                    flash_proxy_usdc_v3 = None

                try:
                    flash_proxy_v3 = GebETHKeeperFlashProxy(
                        web3,
                        Address(conf[
                            f'GEB_UNISWAP_V3_SINGLE_KEEPER_FLASH_PROXY_{name[0]}']
                                ))
                except Exception as e:
                    print(e)
                    flash_proxy_v3 = None

                collateral = Collateral(
                    collateral_type=collateral_type,
                    collateral=collateral,
                    adapter=adapter,
                    collateral_auction_house=coll_auction_house,
                    keeper_flash_proxy=flash_proxy,
                    keeper_flash_proxy_dai_v3=flash_proxy_dai_v3,
                    keeper_flash_proxy_usdc_v3=flash_proxy_usdc_v3,
                    keeper_flash_proxy_v3=flash_proxy_v3,
                    osm=osm)

                collaterals[collateral_type.name] = collateral

            return GfDeployment.Config(
                pause, safe_engine, accounting_engine, tax_collector,
                liquidation_engine, surplus_auction_house, debt_auction_house,
                coin_savings_acct, system_coin, system_coin_adapter, prot,
                oracle_relayer, esm, global_settlement, proxy_registry,
                proxy_actions, safe_manager, uniswap_factory, uniswap_router,
                mc_keeper_flash_proxy, starting_block_number, collaterals)
Beispiel #12
0
 def setup_method(self):
     self.web3 = Web3(HTTPProvider("http://localhost:8555"))
     self.web3.eth.defaultAccount = self.web3.eth.accounts[0]
     self.token = DSToken.deploy(self.web3, 'ABC', 'ABC')
     assert self.token.mint(Wad(100)).transact()
Beispiel #13
0
 def test_fail_when_no_contract_under_that_address(self):
     # expect
     with pytest.raises(Exception):
         DSToken(
             web3=self.web3,
             address=Address('0xdeadadd1e5500000000000000000000000000000'))
Beispiel #14
0
 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.second_address = Address(self.web3.eth.accounts[1])
     self.dstoken = DSToken.deploy(self.web3, 'ABC', 'ABC')
Beispiel #15
0
def setup_function():
    global token
    token = DSToken.deploy(web3, 'ABC', 'ABC')