Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bolychevanton committed Jan 13, 2023
0 parents commit f0af907
Show file tree
Hide file tree
Showing 11 changed files with 1,424 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# dotenv
.env

# virtualenv
.venv
venv/
ENV/
env/
51 changes: 51 additions & 0 deletions README_new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Quotes Telegram Bot

You need to write telegram bot that enable users extract quotes from UniswapV2 DEX and send alerts in case the quote reaches the specific level.

There is a [great lib](https://docs.python-telegram-bot.org/en/stable/examples.html) for creating telegram bots on python. Read the documentantion and understand the details of implementation.

## Functionality

The telegram bot should have the following functionality.

### `/regname`

```
/regname <TOKEN NAME> <TOKEN ADDRESS>
```
should register `<TOKEN NAME>` for `<TOKEN ADDRESS>`. For instance, commands
```
/regname WETH 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
/regname USDT 0xdAC17F958D2ee523a2206206994597C13D831ec7
```
register 2 names WETH and USDT which enable users do not use addresses, but use names instead.

### `/quote`
```
/quote <FOREIGN TOKEN ADDRESS/NAME> <DOMESTIC TOKEN ADDRESS/NAME> [<BLOCK INDENTIFIER>]
```
For instance,
```
/quote WETH USDT
```
should return the current quote in USDT and
```
/quote WETH USDT 16000000
```
should return quote in USDT as of 16000000 block. Note that the commands
```
\quote 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 0xdAC17F958D2ee523a2206206994597C13D831ec7
\quote 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 USDT 16000000
```
should be still valid, i.e. it should be indifferent for user to work either with adresses or with registered names

### `/alert`
```
/alert <FOREIGN TOKEN ADDRESS/NAME> <DOMESTIC TOKEN ADDRESS/NAME> <QUOTE LEVEL>
```
should send alert to user if the price reaches the `<QUOTE LEVEL>`. For instance, current WETH/USDT quote equals 1300. You send the following command to bot
```
/alert WETH USDT 1350
```
In this case the first moment when WETH/USDT is greater than 1350 the telegram bot should send the alert message about the event.

28 changes: 28 additions & 0 deletions const/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
import pathlib
from omegaconf import OmegaConf

PROJECT_DIR = pathlib.Path(__file__).parent.parent.resolve()
JSON_ABIS_DIR = PROJECT_DIR / "const" / "json_abis"

with open(JSON_ABIS_DIR / "uniswapv2_factory.json", "r") as f:
UNISWAPV2_FACTORY_ABI = json.load(f)

with open(JSON_ABIS_DIR / "uniswapv2_pair.json", "r") as f:
UNISWAPV2_PAIR_ABI = json.load(f)

with open(JSON_ABIS_DIR / "erc20.json", "r") as f:
ERC20_ABI = json.load(f)

UNIT_IN_BPS = 10000
DEFAULT_TIMEOUT = 60
ALL_PAIRS_CALL_HEX = (
0x1E3DD18B0000000000000000000000000000000000000000000000000000000000000000
)
BALANCEOF_METHOD_ENCODED = "0x70a08231000000000000000000000000"
GET_RESERVES_METHOD_ENCODED = "0x0902f1ac"
TOKEN1_METHOD_ENCODED = "0xd21220a7"
TOKEN0_METHOD_ENCODED = "0x0dfe1681"


ADDRESSES = OmegaConf.load(PROJECT_DIR / "const" / "addresses.yaml")
3 changes: 3 additions & 0 deletions const/addresses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uniswapv2_factory : "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
sushiswapv2_factory : "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac"
weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
222 changes: 222 additions & 0 deletions const/json_abis/erc20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]
Loading

0 comments on commit f0af907

Please sign in to comment.