Skip to content

Instantly share code, notes, and snippets.

View snowkidind's full-sized avatar
💭
Was informed that there is a special place in hell for pureJS maximalists....

Keny Ruyter snowkidind

💭
Was informed that there is a special place in hell for pureJS maximalists....
View GitHub Profile
@snowkidind
snowkidind / js is bad at numbers...
Created May 25, 2019 14:15
Why on earth does JS do the things it does....
function digits(n) {
return Math.floor(Math.log(n) / Math.log(10));
}
function round10(value, exp) {
return decimalAdjust('round', value, exp);
}
function decimalAdjust(type, value, exp) {
module.exports = {
// given an array of timestamps only, returns a set of relevant timestamps
// to previous hours, only allowing one timestamp per hour
hourlyTimestamps: function (array){
const now = new Date().getTime();
let msh = 3.6e+6; // milliseconds per hour
let hoursGone = 0;
let theseHours = []; // array of representative data on an hourly basis, 0 if no data
let analysisDuration = 168; // hours in a given week.
@snowkidind
snowkidind / caveman.js
Last active May 29, 2020 14:41
Caveman example using SnowSignals model output for simplified forecasting.
// Note: internal implementation. This does not use the snowsignals-api npm package, examples coming soon
// see also http://snowsignals.com:3333/apiDocs
const signalsApi = require('../api.js');
module.exports = {
whatThink: function(job){
return new Promise(async (resolve, reject) => {
job.emaslowemaw = 40;
const chalk = require('chalk');
const player = require('play-sound')();
const eventManager = require('../operations/eventManager');
const diagnostics = require('../utilities/diagnostics.js');
const request = require('request');
let executeTrades = true;
let lastBalanceTime = 0;
let lastBalance;
@snowkidind
snowkidind / deliverableWithFee.js
Last active September 24, 2020 02:37
OMG Network custom transaction example part 2
/*
* deliverableWithFee.js
*
* Storefront application where user purchases ERC20, 721 and
* pays fees in the network's native fee curency.
* Modified version of community-points::transaction.js
* See also
* keny@eastcoastbands.com
*/
/*
* initDeliverable.js
*
* Storefront example application where user purchases ERC20, 721 and
* pays fees in the network's native fee curency.
* This is not a complete application, hence a gist.
* Modified version of community-points::transaction.js
* See also
* keny@eastcoastbands.com
*/
@snowkidind
snowkidind / curveBrownie
Created December 21, 2020 07:38
Notes about getting a mainnet-fork version of curve working for non brownie-centrics
Working with Curve Source Repo, Including running from Brownie.
For starters, there is a pdf manual for brownie that should be found and utilized.
The way to configure the infura or whatever provider is via the command line,
in there you will want to set your mnemonic as well as your infura key or private RPC
$ brownie networks list true
$ brownie networks modify mainnet-fork mnemonic="\"your twelve word mnemonic\""
$ brownie networks modify mainnet host=https://rinkeby.infura.io/v3/dklfjh0g8og8ohg845jhsgr98
@snowkidind
snowkidind / dydx integration
Last active February 26, 2023 23:51
dydx nodejs typescript wrapper WIP
const { DydxClient } = require('@dydxprotocol/v3-client')
const Web3 = require('web3')
const web31 = new Web3(process.env.RPC_NODE)
const web32 = new Web3(process.env.RPC_NODE)
const signer1 = web31.eth.accounts.wallet.add(process.env.TRADING_ZERO_PVT_KEY)
const signer2 = web32.eth.accounts.wallet.add(process.env.TRADING_ONE_PVT_KEY)
const { dateutils } = require('../utils')
const { iso8601, dateNowUTC, timeFmtDb } = dateutils
// load solana transactions into the database
const env = require('node-env-file')
env(__dirname + '/../.env')
const solscan = require('../external/solscan.js')
const { dbLocation, dbChainTx, dbChainTxSync, dbSplAccount, dbKnownWallets } = require('../db')
const { dateutils, decimals, signal, utils } = require('../utils')
const { timeFmtDb, dateNowUTC } = dateutils
const { weiToDisplay, bigD } = decimals
Using const { AlphaRouter } = require('@uniswap/smart-order-router')
when calling
const wei = ethers.utils.parseUnits('100', 6)
const inputAmount = CurrencyAmount.fromRawAmount(USDC, jsbi.BigInt(wei)) // Note inputAmount contains its own JSBI's created by uniswap code which appear to be the source of the error
const route = await router.route(
inputAmount,
UNI,
TradeType.EXACT_INPUT,
{