Skip to content

Instantly share code, notes, and snippets.

View riordant's full-sized avatar
💯

tadhg riordant

💯
View GitHub Profile
@riordant
riordant / DSMath-ethers.js
Created February 8, 2021 16:24
ethers DSMath - perform decimal precision operations with ethers BigNumber. Adapted from Solidity DSMath library.
const { ethers } = require("ethers");
BigNumber = ethers.BigNumber
module.exports = {
WAD: ethers.utils.parseUnits('1'),
//rounds to zero if x*y < WAD / 2
wmul: function(x, y) {
return x.mul(y).add(WAD.div(2)).div(WAD);
},
@riordant
riordant / geth-dev-mode.sh
Last active November 29, 2021 09:50
Geth Gananche emulator - set up Geth like Ganache. Geth produces better debugging output for Remix and Truffle Debug.
# cd ~/.geth/
# Add following script here
# Create ~/.geth/keys, ~/geth/dev
# Add keys 0.txt,1.txt..N.txt, and passwords.txt, with each line in passwords.txt representing password for that account
# import into ~/geth/dev: geth account import --datadir ~/.geth/chain ~/.geth/dev/0.txt etc., enter same password
@riordant
riordant / miner.js
Created January 21, 2021 09:06
Miner for ganache-cli. run ganache-cli -d and this will mine blocks at an average of 5 seconds.
var ethers = require('ethers');
// ganache deterministic mnemonic
const mnemonic = 'myth like bonus scare over problem client lizard pioneer submit female collect';
// use last funded account
const account = "m/44'/60'/0'/0/9";
// default ganache provider
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545");
function getRandomInt(min, max) {
@riordant
riordant / TokenWithNameSymbolChange.sol
Created January 6, 2021 06:51
OpenZeppelin ERC20 token with changeable name/symbol
pragma solidity ^0.5.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20Detailed.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/ownership/Ownable.sol";
contract Token is ERC20, ERC20Detailed, Ownable {
string private _name = "DAOMaker Token";
string private _symbol = "DAO";
@riordant
riordant / account_liquidity_balancer.js
Created November 27, 2020 07:26
Get info on provided address for provided Balancer pool.
// npm install axios
// node account_liquidity_balancer.js
axios = require('axios')
// variables
const poolId = "0xd3d14de568990854705c40221f75efbad8c0c981";
const userAddress = "0x64a63ef1b19519be8afb9080e5725bd608d6f389";
async function getPool(poolId, userAddress) {
const response = await axios({
@riordant
riordant / account_liquidity_uniswap.js
Last active November 11, 2020 04:51
Get Liquidity (in USD) for all token pairings for an account from the UniSwap subgraph.
// npm install @apollo/client node-fetch apollo-link-http
// node account_liquidity_uniswap.js
apolloClient = require('@apollo/client')
fetch = require('node-fetch')
httpLink = require('apollo-link-http')
ApolloClient = apolloClient.ApolloClient
HttpLink = httpLink.HttpLink
InMemoryCache = apolloClient.InMemoryCache
@riordant
riordant / clean_zip_creation.cpp
Created December 21, 2018 16:00
Clean ZIP file creation using minizip in C++
/*
(Extension of the main answer for the question here - https://stackoverflow.com/questions/11370908/how-do-i-use-minizip-on-zlib)
* Creates a ZIP file -
after specifying an absolute path to a "root" directory, all filepaths derived from this path are stored in the ZIP file,
with only files and their paths from the root preserved.
eg. root path: /a/b/c/d/
filepaths(from root path): e/f.txt
g.dat
//to accompany ethers_structs.js
pragma solidity 0.4.21;
pragma experimental ABIEncoderV2;
contract TestContract {
struct SubStruct {
uint256 id;
string description;
}
// setup ethers.js, sends an instance of a struct to an external function, and returns it the instance values.
//load in node: .load ~/path/to/file/ethers_setup.js
//first run testrpc locally.
var privkey = "0x{privkey}" //insert privkey from testrpc here
//dependancies
var solc = require('solc') //include solc application
var fs = require('fs') //include node file manipulation module
@riordant
riordant / bittrex_get_usdt_balance.py
Last active January 13, 2018 01:37
A script to get your total USDT balance on Bittrex via the API. Create API/secret combo on Bittrex and insert under 'key' and 'secret'
from time import time
import hashlib
import hmac
import requests
key = "API_KEY"
secret = "SECRET_KEY"
nonce = str(int(time() * 1000))
#sign and call the url.