Esempio n. 1
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")
        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_dai = DSToken.deploy(self.web3, 'DAI')
        self.ds_usdc = DSToken.deploy(self.web3, 'USDC')
        self.token_dai = Token("DAI", self.ds_dai.address, 18)
        self.token_usdc = Token("USDC", self.ds_usdc.address, 6)
        self.token_weth = Token("WETH", self.weth_address, 18)

        self.dai_usdc_uniswap = UniswapV2(self.web3, self.token_dai, self.token_usdc, self.our_address, self.router_address, self.factory_address)
        self.dai_eth_uniswap = UniswapV2(self.web3, self.token_dai, self.token_weth, self.our_address, self.router_address, self.factory_address)
        
        ## Useful for debugging failing transactions
        logger = logging.getLogger('eth')
        logger.setLevel(8)
Esempio n. 2
0
    def setup_class(self):
        self.web3 = Web3(HTTPProvider("http://0.0.0.0:8555", request_kwargs={'timeout': 10}))
        self.web3.eth.defaultAccount = Web3.toChecksumAddress("0x9596C16D7bF9323265C2F2E22f43e6c80eB3d943")
        register_private_key(self.web3, "0x91cf2cc3671a365fcbf38010ff97ee31a5b7e674842663c56769e41600696ead")

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

        # reset ganache EVM state to genesis
        session = requests.Session()
        method = 'evm_revert'
        params = [1]
        payload = {"jsonrpc": "2.0",
                   "method": method,
                   "params": params,
                   "id": 1}
        headers = {'Content-type': 'application/json'}
        response = session.post('http://0.0.0.0:8555', json=payload, headers=headers)
        print("revert response: ", response)

        # constructor args for SwapRouter
        self.factory_address: Address = self._deploy(self.web3, self.UniswapV3Factory_abi, self.UniswapV3Factory_bin, [])
        self.weth_address: Address = self._deploy(self.web3, self.weth_abi, self.weth_bin, [])
        self.token_descriptor_address: Address = self._deploy(self.web3, self.NFTDescriptor_abi, self.NFTDescriptor_bin, [])

        self.swap_router_address = self._deploy(self.web3, self.SwapRouter_abi, self.SwapRouter_bin, [self.factory_address.address, self.weth_address.address])
        self.nonfungiblePositionManager_address = self._deploy(self.web3, self.NonfungiblePositionManager_abi, self.NonfungiblePositionManager_bin, [self.factory_address.address, self.weth_address.address, self.token_descriptor_address.address])
        self.tick_lens_address = self._deploy(self.web3, self.UniswapV3TickLens_abi, self.UniswapV3TickLens_bin, [])
        self.quoter_address = self._deploy(self.web3, self.Quoter_abi, self.Quoter_bin, [self.factory_address.address, self.weth_address.address])

        self.position_manager = PositionManager(self.web3, self.nonfungiblePositionManager_address, self.factory_address, self.tick_lens_address, self.weth_address)
        self.swap_router = SwapRouter(self.web3, self.swap_router_address, self.quoter_address)

        ## Useful for debugging failing transactions
        logger = logging.getLogger('eth')
        logger.setLevel(8)
        # Transact.gas_estimate_for_bad_txs = 210000

        self.ds_dai = DSToken.deploy(self.web3, 'DAI')
        self.ds_usdc = DSToken.deploy(self.web3, 'USDC')
        self.token_dai = Token("DAI", self.ds_dai.address, 18)
        self.token_usdc = Token("USDC", self.ds_usdc.address, 6)
        self.token_weth = Token("WETH", self.weth_address, 18)

        self.position_manager.approve(self.token_dai)
        self.position_manager.approve(self.token_usdc)
        self.position_manager.approve(self.token_weth)
        self.swap_router.approve(self.token_dai)
        self.swap_router.approve(self.token_usdc)
        self.swap_router.approve(self.token_weth)

        # TODO: normalize amounts for decimals
        dai_balance = Wad.from_number(9000000000000000)
        usdc_balance = Wad.from_number(900000000000000)

        self.ds_dai.mint(dai_balance).transact(from_address=self.our_address)
        self.ds_usdc.mint(self.token_usdc.unnormalize_amount(usdc_balance)).transact(from_address=self.our_address)
Esempio 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.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))
Esempio n. 4
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")
        register_private_key(self.web3, "0x91cf2cc3671a365fcbf38010ff97ee31a5b7e674842663c56769e41600696ead")
        self.our_address = Address(self.web3.eth.defaultAccount)

        self.ds_reward_token = DSToken.deploy(self.web3, 'REWARD')
        self.reward_token = Token("REWARD", self.ds_reward_token.address, 18)

        # Deploy UniswapV2 contracts and set liquidity token
        self.liquidity_token = self.deploy_liquidity_token()

        self.staking_rewards_address = self._deploy(self.web3, self.staking_rewards_abi, self.staking_rewards_bin, [self.our_address.address, self.reward_token.address.address, self.liquidity_token.address.address])

        self.uniswap_staking_rewards = UniswapStakingRewards(self.web3, self.our_address, Address(self.staking_rewards_address), "UniswapStakingRewards")

        ## Useful for debugging failing transactions
        logger = logging.getLogger('eth')
        logger.setLevel(8)
Esempio n. 5
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))
Esempio n. 6
0
    def setup_class(self):
        # Use Ganache docker container
        self.web3 = Web3(
            HTTPProvider("http://0.0.0.0:8555", request_kwargs={'timeout':
                                                                60}))
        self.web3.eth.defaultAccount = Web3.toChecksumAddress(
            "0x9596C16D7bF9323265C2F2E22f43e6c80eB3d943")
        register_private_key(
            self.web3,
            "0x91cf2cc3671a365fcbf38010ff97ee31a5b7e674842663c56769e41600696ead"
        )

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

        # take snapshot of ganache EVM state at genesis
        session = requests.Session()
        method = 'evm_snapshot'
        params = []
        payload = {
            "jsonrpc": "2.0",
            "method": method,
            "params": params,
            "id": 1
        }
        headers = {'Content-type': 'application/json'}
        response = session.post('http://0.0.0.0:8555',
                                json=payload,
                                headers=headers)

        # constructor args for nonfungiblePositionManager
        self.factory_address: Address = self._deploy(self.web3,
                                                     self.UniswapV3Factory_abi,
                                                     self.UniswapV3Factory_bin,
                                                     [])
        self.weth_address: Address = self._deploy(self.web3, self.weth_abi,
                                                  self.weth_bin, [])
        self.token_descriptor_address: Address = self._deploy(
            self.web3, self.NFTDescriptor_abi, self.NFTDescriptor_bin, [])

        self.nonfungiblePositionManager_address = self._deploy(
            self.web3, self.NonfungiblePositionManager_abi,
            self.NonfungiblePositionManager_bin, [
                self.factory_address.address, self.weth_address.address,
                self.token_descriptor_address.address
            ])

        self.tick_lens_address = self._deploy(self.web3,
                                              self.UniswapV3TickLens_abi,
                                              self.UniswapV3TickLens_bin, [])
        self.position_manager = PositionManager(
            self.web3, self.nonfungiblePositionManager_address,
            self.factory_address, self.tick_lens_address, self.weth_address)

        self.swap_router_address = self._deploy(
            self.web3, self.SwapRouter_abi, self.SwapRouter_bin,
            [self.factory_address.address, self.weth_address.address])
        self.quoter_address = self._deploy(
            self.web3, self.Quoter_abi, self.Quoter_bin,
            [self.factory_address.address, self.weth_address.address])

        self.swap_router = SwapRouter(self.web3, self.swap_router_address,
                                      self.quoter_address)

        ## Useful for debugging failing transactions
        logger = logging.getLogger('eth')
        logger.setLevel(8)
        Transact.gas_estimate_for_bad_txs = 210000
Esempio n. 7
0
#w3.eth.defaultAccount = "ethAccount"
#register_private_key(w3, "PrivateKey")
#TEST_LEV_ADDRESS='LevAddress'
#TEST_DAI_ADDRESS='DaiAddress'
#TEST_REP_ADDRESS='RepAddress'
#TEST_ETH_ADDRESS='0x0000000000000000000000000000000000000000'

#leverj = LeverjAPI(w3, "LeverjWebsiteAddress", "AccountID","apiKey","secret"  ,9.5)


leverj_custodian = LeverJ(w3, custodian_address)
'''

w3 = Web3(Web3.HTTPProvider(sys.argv[1], request_kwargs={'timeout': 60}))
w3.eth.defaultAccount = sys.argv[2]
register_private_key(w3, sys.argv[3])

leverj = LeverjAPI(w3, sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[7], 9.5)
leverj_custodian = LeverJ(w3, Address(sys.argv[8]))

print("get balances")
print(leverj.get_balances())

print("get balances for ETH")
print(leverj.get_balance("ETH"))

print("get balances for DAI")
print(f"type of dai balance is {type(leverj.get_balance('DAI'))}")
print(leverj.get_balance("DAI"))

print("getting LEVETH instrument from get_product")
Esempio n. 8
0
USDC_KOVAN_ADDRESS = Address("0x198419c5c340e8de47ce4c0e4711a03664d42cb2")

weth_token_kovan = Token("WETH", WETH_KOVAN_ADDRESS, 18)
weth_token_mainnet = Token("WETH", mainnet_weth_address, 18)
dai_token_kovan = Token("DAI", DAI_KOVAN_ADDRESS, 18)
dai_token_mainnet = Token("DAI", DAI_MAINNET_ADDRESS, 18)
usdc_token_kovan = Token("USDC", USDC_KOVAN_ADDRESS, 6)

provider = sys.argv[1]
private_key = sys.argv[2]
account_address = Address(sys.argv[3])

http_provider = HTTPProvider(provider)
web3 = Web3(http_provider)
web3.eth.defaultAccount = Web3.toChecksumAddress(account_address.address)
register_private_key(web3, private_key)

# useful for debugging
Transact.gas_estimate_for_bad_txs = 210000

# position_manager_mainnet = PositionManager(web3, position_manager_address, factory_address, ticklens_address, mainnet_weth_address)
position_manager_kovan = PositionManager(web3, position_manager_address, factory_address, ticklens_address,
                                         WETH_KOVAN_ADDRESS)

### mainnet pool data
# weth_dai_medium_fee_pool_address_mainnet = position_manager_mainnet.get_pool_address(weth_token_mainnet, dai_token_mainnet, 3000)
# print(weth_dai_medium_fee_pool_address_mainnet)
#
# weth_dai_mainnet_pool = position_manager_mainnet.get_pool(weth_dai_medium_fee_pool_address_mainnet, weth_token_mainnet, dai_token_mainnet, 1)
# print("mainnet pool", weth_dai_mainnet_pool)
Esempio n. 9
0
from pymaker import Address, Wad
from pymaker.keys import register_key_file, register_private_key
from pymaker.zrxv2 import ZrxExchangeV2, Asset
from pymaker.token import ERC20Token

# Infura and own wallet settings
logging.basicConfig(format='%(asctime)-15s %(levelname)-8s %(message)s', level=logging.INFO)
WEB3_INFURA_API_KEY = "infura project id here"
INFURA_URL = "https://mainnet.infura.io/v3/" + WEB3_INFURA_API_KEY
WALLET_ADDRESS = "eth wallet address here"
WALLET_PRIVATE_KEY = "pkey of eth wallet address here"

# setting Infura provider and import external pkey
infura_provider = HTTPProvider(INFURA_URL)
web3 = Web3(infura_provider)
register_private_key(web3, WALLET_PRIVATE_KEY)
web3.eth.defaultAccount = WALLET_ADDRESS
EXCHANGE_ADDRESS = Address("0x4f833a24e1f95d70f028921e27040ca56e09ab0b")

zrx_v2_exchange = ZrxExchangeV2(web3=web3, address=EXCHANGE_ADDRESS)
ethfinex_trustless_api = TEthfinexApi(zrx_v2_exchange, 'https://api.ethfinex.com', 15.5)

ethfinex_symbol = ethfinex_trustless_api.get_symbols()
ethfinex_symbols_details = ethfinex_trustless_api.get_symbols_details()
ethfinex_config = ethfinex_trustless_api.get_config()['0x']

ETHFINEX_ADDRESS = Address(ethfinex_config['ethfinexAddress'])
#EXCHANGE_ADDRESS = Address(ethfinex_config['exchangeAddress'])

DAI_WRAPPER_ADDRESS = Address(ethfinex_config['tokenRegistry']['DAI']['wrapperAddress'])
DAI_TOKEN_ADDRESS = Address(ethfinex_config['tokenRegistry']['DAI']['tokenAddress'])