Skip to content

Instantly share code, notes, and snippets.

@amitkot
amitkot / PriceOracleInterfaceABI.json
Created December 18, 2018 07:15
DutchExchange PriceOracleInterface ABI with modified getUSDETHPrice() function that has stateMutability "view"
[
{
"constant": true,
"inputs": [],
"name": "emergencyMode",
"outputs": [
{
"name": "",
"type": "bool"
}
pragma solidity ^0.4.24;
// File: contracts/ERC20Interface.sol
// https://github.com/ethereum/EIPs/issues/20
interface ERC20 {
function totalSupply() public view returns (uint supply);
function balanceOf(address _owner) public view returns (uint balance);
function transfer(address _to, uint _value) public returns (bool success);
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
@amitkot
amitkot / decimals.py
Last active December 12, 2018 10:58
Fun with decimals, useful for big numbers
from decimal import Decimal
import re
def ddiff(str):
numbers = re.findall(r'\d+', str)
print(f'0: {numbers[0]}')
print(f'1: {numbers[1]}')
print(f'diff: {Decimal(numbers[0]) - Decimal(numbers[1])}')
def dsum():
@amitkot
amitkot / dxmm.js
Created October 17, 2018 08:39
DutchX marker making bot tests [WIP]
const BigNumber = web3.BigNumber
const Helper = require("./helper.js")
require("chai")
.use(require("chai-as-promised"))
.use(require('chai-bignumber')(BigNumber))
.should()
const DutchExchange = artifacts.require("DutchExchange")
const DxMarketMaker = artifacts.require("DxMarketMaker")
var Web3 = require('web3');
//url = "http://localhost:8545/jsonrpc";
url = "https://mainnet.infura.io";
//url = "http://13.229.54.28:8545/"; // override
var web3 = new Web3(new Web3.providers.HttpProvider(url));
var BigNumber = web3.utils.BN;
var fs = require("fs");
icoAbi = [{"constant":true,"inputs":[],"name":"cappedSaleStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"openSaleStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"list","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"contributor","type":"address"},{"name":"amountInWei","type":"uint256"}],"name":"eligible","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"contributor","type":"address"}],"name":"contributorCap","outputs":[{"name":"","type":"uint256"}],"payable":false,"type"
@amitkot
amitkot / testing_guidelines.md
Last active June 24, 2018 07:35
Testing Guidelines

Testing Guidelines

Test Only Public API

Testing internal implementation leads to fragile tests that break often for no good reason.

We should try to make very clear in our code what is part of a class's API and what is internal implementation. Internal implementation should be named accordingly (e.g. using a single underscore prefix in Python).

Internal implementation of a class (whether class attribute or method) should not be accessed directly from outside the class. This includes other classes using it but also includes tests. Unit tests should only call the classes public API, as the internal implementation might change without notice and should not break the tests.

@amitkot
amitkot / Cropping orders by timestamp from Redis RDB dump.ipynb
Created May 29, 2018 09:05
Cropping orders by timestamp from Redis RDB dump
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amitkot
amitkot / highlight_py.sh
Created May 15, 2018 18:59
Shell script for highlighting source python code
pbpaste | /usr/local/bin/pygmentize -f rtf -O "style=borland,fontface=Inconsolata,fontsize=60" -l python3 | pbcopy
@amitkot
amitkot / network.py
Created May 13, 2018 08:08
Checking new NetworkError
from enum import Enum, auto
from json import dumps
from urllib.parse import urlencode, unquote, urlparse, parse_qsl, ParseResult
import aiohttp
import async_timeout
from aiohttp import ClientError
from pricemonitor.exceptions import PriceMonitorException
@amitkot
amitkot / all_token_prices.py
Created May 3, 2018 14:40
Alternative version of all_token_prices that uses gather
import asyncio
import itertools
from typing import List, Any, Iterable
from pricemonitor.config import Coin
from pricemonitor.producing.data_producer import DataProducer, PairPrice
from pricemonitor.producing.exchange_prices import ExchangePrices
from pricemonitor.producing.feed_prices import FeedPrices