Ejemplo n.º 1
0
    def approval_function(token: ERC20Token, spender_address: Address, spender_name: str):
        address_to_check = kwargs['from_address'] if 'from_address' in kwargs else Address(
            token.web3.eth.defaultAccount)

        move_contract = Contract._get_contract(web3=token.web3, abi=move_abi, address=token.address)
        if move_contract.call().can(address_to_check.address, spender_address.address) is False:
            logger = logging.getLogger()
            logger.info(f"Approving {spender_name} ({spender_address}) to move our {token.address} directly")
            if not move_contract.functions.hope(spender_address.address).transact(**kwargs):
                raise RuntimeError("Approval failed!")
Ejemplo n.º 2
0
    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")
        self.our_address = Address(self.web3.eth.defaultAccount)

        self.private_key = "0x91cf2cc3671a365fcbf38010ff97ee31a5b7e674842663c56769e41600696ead"
        register_private_key(self.web3, self.private_key)

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

        self.deploy_tokens()

        token_config = {
            "tokens": {
                "DAI": {
                    "tokenAddress": self.ds_dai.address.address
                },
                "KEEP": {
                    "tokenAddress": self.ds_keep.address.address
                },
                "LEV": {
                    "tokenAddress": self.ds_lev.address.address,
                    "tokenDecimals": 9
                },
                "USDC": {
                    "tokenAddress": self.ds_usdc.address.address,
                    "tokenDecimals": 6
                },
                "WBTC": {
                    "tokenAddress": self.ds_wbtc.address.address,
                    "tokenDecimals": 8
                },
                "WETH": {
                    "tokenAddress": self.weth_address.address
                }
            }
        }
        # write token config with locally deployed addresses to file
        with open("test-token-config.json", "w+") as outfile:
            outfile.write(json.dumps(token_config))
Ejemplo n.º 3
0
    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")
        self.our_address = Address(self.web3.eth.defaultAccount)

        self.private_key = "0x91cf2cc3671a365fcbf38010ff97ee31a5b7e674842663c56769e41600696ead"
        register_private_key(self.web3, self.private_key)

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

        self.ds_dai = DSToken.deploy(self.web3, 'DAI')
        self.ds_dai.mint(
            Wad.from_number(500)).transact(from_address=self.our_address)
        self.token_dai = Token("DAI", self.ds_dai.address, 18)
        self.token_weth = Token("WETH", self.weth_address, 18)

        token_config = {
            "tokens": {
                "DAI": {
                    "tokenAddress": self.ds_dai.address.address
                },
                "WETH": {
                    "tokenAddress": self.weth_address.address
                }
            }
        }
        # write token config with locally deployed addresses to file
        with open("test-token-config.json", "w+") as outfile:
            outfile.write(json.dumps(token_config))