Skip to content

Instantly share code, notes, and snippets.

@amitkot
Created January 8, 2019 19:02
Show Gist options
  • Save amitkot/e5441f427cc21a6e3a9e5b3b1fbbd951 to your computer and use it in GitHub Desktop.
Save amitkot/e5441f427cc21a6e3a9e5b3b1fbbd951 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 116,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: web3 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (4.8.2)\n",
"Requirement already satisfied: cytoolz<1.0.0,>=0.9.0; implementation_name == \"cpython\" in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (0.9.0.1)\n",
"Requirement already satisfied: hexbytes<1.0.0,>=0.1.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (0.1.0)\n",
"Requirement already satisfied: eth-account<0.4.0,>=0.2.1 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (0.3.0)\n",
"Requirement already satisfied: websockets<7.0.0,>=6.0.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (6.0)\n",
"Requirement already satisfied: eth-abi<2.0.0,>=1.2.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (1.3.0)\n",
"Requirement already satisfied: lru-dict<2.0.0,>=1.1.6 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (1.1.6)\n",
"Requirement already satisfied: eth-utils<2.0.0,>=1.2.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (1.4.1)\n",
"Requirement already satisfied: eth-hash[pycryptodome]<1.0.0,>=0.2.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (0.2.0)\n",
"Requirement already satisfied: requests<3.0.0,>=2.16.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from web3) (2.21.0)\n",
"Requirement already satisfied: toolz>=0.8.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from cytoolz<1.0.0,>=0.9.0; implementation_name == \"cpython\"->web3) (0.9.0)\n",
"Requirement already satisfied: eth-keys<0.3.0,>=0.2.0b3 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-account<0.4.0,>=0.2.1->web3) (0.2.0b3)\n",
"Requirement already satisfied: attrdict<3,>=2.0.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-account<0.4.0,>=0.2.1->web3) (2.0.0)\n",
"Requirement already satisfied: eth-keyfile<0.6.0,>=0.5.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-account<0.4.0,>=0.2.1->web3) (0.5.1)\n",
"Requirement already satisfied: eth-rlp<1,>=0.1.2 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-account<0.4.0,>=0.2.1->web3) (0.1.2)\n",
"Requirement already satisfied: eth-typing<3.0.0,>=2.0.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-abi<2.0.0,>=1.2.0->web3) (2.0.0)\n",
"Requirement already satisfied: parsimonious<0.9.0,>=0.8.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-abi<2.0.0,>=1.2.0->web3) (0.8.1)\n",
"Requirement already satisfied: pycryptodome<4,>=3.6.6; extra == \"pycryptodome\" in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-hash[pycryptodome]<1.0.0,>=0.2.0->web3) (3.7.2)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from requests<3.0.0,>=2.16.0->web3) (2018.11.29)\n",
"Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from requests<3.0.0,>=2.16.0->web3) (3.0.4)\n",
"Requirement already satisfied: idna<2.9,>=2.5 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from requests<3.0.0,>=2.16.0->web3) (2.8)\n",
"Requirement already satisfied: urllib3<1.25,>=1.21.1 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from requests<3.0.0,>=2.16.0->web3) (1.24.1)\n",
"Requirement already satisfied: six in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from attrdict<3,>=2.0.0->eth-account<0.4.0,>=0.2.1->web3) (1.12.0)\n",
"Requirement already satisfied: rlp<2,>=0.6.0 in /Users/amit/.local/share/virtualenvs/contract_interaction-CZR2Bi-j/lib/python3.6/site-packages (from eth-rlp<1,>=0.1.2->eth-account<0.4.0,>=0.2.1->web3) (1.0.3)\n"
]
}
],
"source": [
"!pip install web3"
]
},
{
"cell_type": "code",
"execution_count": 109,
"metadata": {},
"outputs": [],
"source": [
"import itertools\n",
"\n",
"from web3 import Web3\n",
"from web3.contract import ConciseContract\n",
"\n",
"\n",
"MAINNET = \"https://infura.io\"\n",
"KOVAN = \"https://kovan.infura.io\"\n",
"RINKEBY = \"https://rinkeby.infura.io\"\n",
"\n",
"NET = RINKEBY\n",
"\n",
"w3 = Web3(Web3.HTTPProvider(NET))"
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {},
"outputs": [],
"source": [
"factoryABI = '[{\"name\": \"NewExchange\", \"inputs\": [{\"type\": \"address\", \"name\": \"token\", \"indexed\": true}, {\"type\": \"address\", \"name\": \"exchange\", \"indexed\": true}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"initializeFactory\", \"outputs\": [], \"inputs\": [{\"type\": \"address\", \"name\": \"template\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 35725}, {\"name\": \"createExchange\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"token\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 187911}, {\"name\": \"getExchange\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"token\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 715}, {\"name\": \"getToken\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"exchange\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 745}, {\"name\": \"getTokenWithId\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"token_id\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 736}, {\"name\": \"exchangeTemplate\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 633}, {\"name\": \"tokenCount\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 663}]'\n",
"exchangeABI = '[{\"name\": \"TokenPurchase\", \"inputs\": [{\"type\": \"address\", \"name\": \"buyer\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"eth_sold\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"tokens_bought\", \"indexed\": true}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"EthPurchase\", \"inputs\": [{\"type\": \"address\", \"name\": \"buyer\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"tokens_sold\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"eth_bought\", \"indexed\": true}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"AddLiquidity\", \"inputs\": [{\"type\": \"address\", \"name\": \"provider\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"eth_amount\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"token_amount\", \"indexed\": true}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"RemoveLiquidity\", \"inputs\": [{\"type\": \"address\", \"name\": \"provider\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"eth_amount\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"token_amount\", \"indexed\": true}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"Transfer\", \"inputs\": [{\"type\": \"address\", \"name\": \"_from\", \"indexed\": true}, {\"type\": \"address\", \"name\": \"_to\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"_value\", \"indexed\": false}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"Approval\", \"inputs\": [{\"type\": \"address\", \"name\": \"_owner\", \"indexed\": true}, {\"type\": \"address\", \"name\": \"_spender\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"_value\", \"indexed\": false}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"setup\", \"outputs\": [], \"inputs\": [{\"type\": \"address\", \"name\": \"token_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 175875}, {\"name\": \"addLiquidity\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"min_liquidity\"}, {\"type\": \"uint256\", \"name\": \"max_tokens\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}], \"constant\": false, \"payable\": true, \"type\": \"function\", \"gas\": 82605}, {\"name\": \"removeLiquidity\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}, {\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"amount\"}, {\"type\": \"uint256\", \"name\": \"min_eth\"}, {\"type\": \"uint256\", \"name\": \"min_tokens\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 116814}, {\"name\": \"__default__\", \"outputs\": [], \"inputs\": [], \"constant\": false, \"payable\": true, \"type\": \"function\"}, {\"name\": \"ethToTokenSwapInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"min_tokens\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}], \"constant\": false, \"payable\": true, \"type\": \"function\", \"gas\": 12757}, {\"name\": \"ethToTokenTransferInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"min_tokens\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}], \"constant\": false, \"payable\": true, \"type\": \"function\", \"gas\": 12965}, {\"name\": \"ethToTokenSwapOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}], \"constant\": false, \"payable\": true, \"type\": \"function\", \"gas\": 50455}, {\"name\": \"ethToTokenTransferOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}], \"constant\": false, \"payable\": true, \"type\": \"function\", \"gas\": 50663}, {\"name\": \"tokenToEthSwapInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"min_eth\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 47503}, {\"name\": \"tokenToEthTransferInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"min_eth\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 47712}, {\"name\": \"tokenToEthSwapOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"eth_bought\"}, {\"type\": \"uint256\", \"name\": \"max_tokens\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 50175}, {\"name\": \"tokenToEthTransferOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"eth_bought\"}, {\"type\": \"uint256\", \"name\": \"max_tokens\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 50384}, {\"name\": \"tokenToTokenSwapInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"min_tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"min_eth_bought\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"token_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 51007}, {\"name\": \"tokenToTokenTransferInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"min_tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"min_eth_bought\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}, {\"type\": \"address\", \"name\": \"token_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 51098}, {\"name\": \"tokenToTokenSwapOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"max_tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"max_eth_sold\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"token_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 54928}, {\"name\": \"tokenToTokenTransferOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"max_tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"max_eth_sold\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}, {\"type\": \"address\", \"name\": \"token_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 55019}, {\"name\": \"tokenToExchangeSwapInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"min_tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"min_eth_bought\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"exchange_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 49342}, {\"name\": \"tokenToExchangeTransferInput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"min_tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"min_eth_bought\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}, {\"type\": \"address\", \"name\": \"exchange_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 49532}, {\"name\": \"tokenToExchangeSwapOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"max_tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"max_eth_sold\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"exchange_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 53233}, {\"name\": \"tokenToExchangeTransferOutput\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}, {\"type\": \"uint256\", \"name\": \"max_tokens_sold\"}, {\"type\": \"uint256\", \"name\": \"max_eth_sold\"}, {\"type\": \"uint256\", \"name\": \"deadline\"}, {\"type\": \"address\", \"name\": \"recipient\"}, {\"type\": \"address\", \"name\": \"exchange_addr\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 53423}, {\"name\": \"getEthToTokenInputPrice\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"eth_sold\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 5542}, {\"name\": \"getEthToTokenOutputPrice\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_bought\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 6872}, {\"name\": \"getTokenToEthInputPrice\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"tokens_sold\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 5637}, {\"name\": \"getTokenToEthOutputPrice\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"eth_bought\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 6897}, {\"name\": \"tokenAddress\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1413}, {\"name\": \"factoryAddress\", \"outputs\": [{\"type\": \"address\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1443}, {\"name\": \"balanceOf\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_owner\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1645}, {\"name\": \"transfer\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_to\"}, {\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 75034}, {\"name\": \"transferFrom\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_from\"}, {\"type\": \"address\", \"name\": \"_to\"}, {\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 110907}, {\"name\": \"approve\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_spender\"}, {\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 38769}, {\"name\": \"allowance\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_owner\"}, {\"type\": \"address\", \"name\": \"_spender\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1925}, {\"name\": \"name\", \"outputs\": [{\"type\": \"bytes32\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1623}, {\"name\": \"symbol\", \"outputs\": [{\"type\": \"bytes32\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1653}, {\"name\": \"decimals\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1683}, {\"name\": \"totalSupply\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1713}]'\n",
"tokenABI = '[{\"name\": \"Transfer\", \"inputs\": [{\"type\": \"address\", \"name\": \"_from\", \"indexed\": true}, {\"type\": \"address\", \"name\": \"_to\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"_value\", \"indexed\": false}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"Approval\", \"inputs\": [{\"type\": \"address\", \"name\": \"_owner\", \"indexed\": true}, {\"type\": \"address\", \"name\": \"_spender\", \"indexed\": true}, {\"type\": \"uint256\", \"name\": \"_value\", \"indexed\": false}], \"anonymous\": false, \"type\": \"event\"}, {\"name\": \"__init__\", \"outputs\": [], \"inputs\": [{\"type\": \"bytes32\", \"name\": \"_name\"}, {\"type\": \"bytes32\", \"name\": \"_symbol\"}, {\"type\": \"uint256\", \"name\": \"_decimals\"}, {\"type\": \"uint256\", \"name\": \"_supply\"}], \"constant\": false, \"payable\": false, \"type\": \"constructor\"}, {\"name\": \"deposit\", \"outputs\": [], \"inputs\": [], \"constant\": false, \"payable\": true, \"type\": \"function\", \"gas\": 74279}, {\"name\": \"withdraw\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 108706}, {\"name\": \"totalSupply\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 543}, {\"name\": \"balanceOf\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_owner\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 745}, {\"name\": \"transfer\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_to\"}, {\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 74698}, {\"name\": \"transferFrom\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_from\"}, {\"type\": \"address\", \"name\": \"_to\"}, {\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 110600}, {\"name\": \"approve\", \"outputs\": [{\"type\": \"bool\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_spender\"}, {\"type\": \"uint256\", \"name\": \"_value\"}], \"constant\": false, \"payable\": false, \"type\": \"function\", \"gas\": 37888}, {\"name\": \"allowance\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [{\"type\": \"address\", \"name\": \"_owner\"}, {\"type\": \"address\", \"name\": \"_spender\"}], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 1025}, {\"name\": \"name\", \"outputs\": [{\"type\": \"bytes32\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 723}, {\"name\": \"symbol\", \"outputs\": [{\"type\": \"bytes32\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 753}, {\"name\": \"decimals\", \"outputs\": [{\"type\": \"uint256\", \"name\": \"out\"}], \"inputs\": [], \"constant\": true, \"payable\": false, \"type\": \"function\", \"gas\": 783}]'\n",
"\n",
"factoryAddress = {\n",
" RINKEBY: \"0xf5D915570BC477f9B8D6C0E980aA81757A3AaC36\",\n",
" MAINNET: \"0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95\",\n",
"}\n",
"\n",
"factory = ConciseContract(w3.eth.contract(address=factoryAddress[NET], abi=factoryABI))\n"
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 -> 0x2448eE2641d78CC42D7AD76498917359D961A783 -> 0x77dB9C915809e7BE439D2AB21032B1b8B58F6891\n",
"2 -> 0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85 -> 0x93bB63aFe1E0180d0eF100D774B473034fd60C36\n",
"3 -> 0xF22e3F33768354c9805d046af3C0926f27741B43 -> 0xaBD44a1D1b9Fb0F39fE1D1ee6b1e2a14916D067D\n",
"4 -> 0xDA5B056Cfb861282B4b59d29c9B395bcC238D29B -> 0x9B913956036a3462330B0642B20D3879ce68b450\n",
"5 -> 0x879884c3C46A24f56089f3bBbe4d5e38dB5788C0 -> 0x26C226EBb6104676E593F8A070aD6f25cDa60F8D\n",
"6 -> 0x3195fd025302c62907886B1743405E14a89514B6 -> 0x96cC5FC7deecab897bb5e11a54Ae2B11D0aCA096\n",
"7 -> 0xADb5364643F52771Afeb52A74BE6c21F1bA24342 -> 0x56b238D96150324C98a431eb0D7F326da307E033\n",
"8 -> 0x167c0A202D5dc99DBac22e4d89c683e97fBdD1D1 -> 0xd8d3b99aF987a97D9141237B1d1387c172686e98\n",
"9 -> 0x9FA96f465a75837C310DFb4E50dfF5B15CC11131 -> 0x507484e1432308eFB26AdC346c3F81b40823fF5e\n",
"10 -> 0x2bC0A9926A757443E92F9F1f7cb9062835CfFD31 -> 0x200cF24cE0DeFC9BD6F21419EaF23141dA44776e\n",
"11 -> 0x443420E189D1c05C63aB1165a971fb14c5Fb8E6a -> 0x593C4621bF8B5a438F945e177D065D45C676dEEE\n",
"12 -> 0x4959c7f62051D6b2ed6EaeD3AAeE1F961B145F20 -> 0xC7Dd2a62882acb0EdC87e0FBf73Ee4E22af8936D\n",
"13 -> 0xc778417E063141139Fce010982780140Aa0cD5Ab -> 0x591a8905752C35E8BCbCdc3b34e86Ff449f53423\n"
]
}
],
"source": [
"token = {}\n",
"exchange = {}\n",
"\n",
"def loadSupportedTokens():\n",
" for i in range(1, factory.tokenCount()):\n",
" token_address = factory.getTokenWithId(i)\n",
" if not token_address: continue\n",
"\n",
" token[token_address] = ConciseContract(w3.eth.contract(address=token_address,\n",
" abi=tokenABI))\n",
"\n",
" exchange_address = factory.getExchange(token_address)\n",
" print(f'{i} -> {token_address} -> {exchange_address}')\n",
" exchange[token_address] = ConciseContract(w3.eth.contract(address=factory.getExchange(token_address), \n",
" abi=exchangeABI))\n",
"\n",
"def printExchangeData(e):\n",
" print(f'name: {e.name()}')\n",
" print(f'symbol: {e.symbol()}')\n",
" print(f'totalSupply: {e.totalSupply()}')\n",
" print(f'decimals: {e.decimals()}') \n",
" if e.totalSupply(): \n",
" print(f'getEthToTokenInputPrice: {e.getEthToTokenInputPrice(100)}')\n",
" print(f'getEthToTokenOutputPrice: {e.getEthToTokenOutputPrice(100)}')\n",
"\n",
" print()\n",
"\n",
"def printAllExchangeData():\n",
" for e in exchange.values():\n",
" printExchangeData(e)\n",
" \n",
" \n",
"loadSupportedTokens()\n",
"\n",
"# printExchangeData()"
]
},
{
"cell_type": "code",
"execution_count": 115,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name: b'Uniswap V1\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n",
"symbol: b'UNI-V1\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n",
"totalSupply: 51763725149547178935\n",
"decimals: 18\n",
"getEthToTokenInputPrice: 25405\n",
"getEthToTokenOutputPrice: 1\n",
"\n"
]
}
],
"source": [
"e = exchange['0x2448eE2641d78CC42D7AD76498917359D961A783']\n",
"printExchangeData(e)"
]
},
{
"cell_type": "code",
"execution_count": 113,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"250221550561669124341"
]
},
"execution_count": 113,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.getEthToTokenInputPrice(10**18)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "my-diplay-name",
"language": "python",
"name": "my-virtualenv-name"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment