Skip to content

Instantly share code, notes, and snippets.

🏁
Eth wrangling.

justin j. moses justinjmoses

🏁
Eth wrangling.
Block or report user

Report or block justinjmoses

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View snxdata.js
window.snxData=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catc
@justinjmoses
justinjmoses / sub.js
Last active Dec 1, 2019
Synthetix subgraph websocket
View sub.js
'use strict';
const WebSocket = require('ws');
const client = new WebSocket('wss://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-exchanges', [
'graphql-ws',
]);
client.on('open', () => {
console.log('open');
View async-foreach.js
// Useful if you want to run a bunch of promises in serial (which admittedly isn't very often frankly)
exports.asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
@justinjmoses
justinjmoses / index.html
Created Oct 20, 2019
Synthetix top holders lock status
View index.html
<header><img src="https://developer.synthetix.io/api/img/logo.png" /></header>
<main>
<p class="helper-text">Note: these results aren't strictly ordered to increase performance.</p>
<button name="begin">Begin</button>
<button name="stop">Stop</button>
<ul>
<li id="tokenHolders"><strong>Token Holders:</strong><var>?</var></li>
@justinjmoses
justinjmoses / totalIssuedSynths.js
Created Jul 3, 2019
Get total issued debt at some specific block
View totalIssuedSynths.js
const { SynthetixJs } = require('synthetix-js');
const snxjs = new SynthetixJs();
(async () => {
const provider = snxjs.ethers.getDefaultProvider();
const currentBlock = await provider.getBlockNumber();
const totalDebtInSystemAtBlock = await snxjs.Synthetix.contract.totalIssuedSynths(
snxjs.utils.toUtf8Bytes4('sUSD'),
@justinjmoses
justinjmoses / exchanges.js
Created Jul 3, 2019
Get all SynthExchange events in the last 24hours using The Graph
View exchanges.js
const graphAPI = 'https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix';
const ts = Math.floor(Date.now()/1e3);
const oneDayAgo = ts - (3600 * 24);
const response = await fetch(graphAPI, {
method: 'POST',
body: `{"query":"{synthExchanges(orderBy:timestamp, orderDirection:desc, where:{timestamp_gt: ${oneDayAgo}}){id,from,gasPrice,fromAmount,fromCurrencyKey,toCurrencyKey,block,timestamp,toAddress}}","variables":null}`
});
const json = await response.json();
@justinjmoses
justinjmoses / vcheck.js
Created May 14, 2019
Node script to check npm version of package (expects piped in versions from npm)
View vcheck.js
'use strict';
const version = process.argv[2];
// Simple script to exit non-zero if the given version
// usage: npm view [package] versions | node vcheck [version]
// eg: npm view synthetix versions | node vcheck 2.4.1
process.stdin
.resume()
.setEncoding('utf8')
@justinjmoses
justinjmoses / random-split.js
Created Dec 4, 2018
Function to split up some given number into a fixed number of parts.
View random-split.js
const random = require('random-js')();
// Splits up number into times random parts
const splitter = (number, times) => {
const ran = random.real(0, number);
if (times < 2) {
return [number];
}
const halved = times / 2;
if (times % 2 === 0) {
@justinjmoses
justinjmoses / EOS Smart Contract Development.md
Last active Nov 12, 2018
Getting started writing Smart Contracts with EOS
View EOS Smart Contract Development.md

Getting started writing Smart Contracts with EOS

This information has been extrapolated from https://developers.eos.io/eosio-home/docs

Latest version of EOS when writing: 1.4.0

Note: the Developer Portal has a number of older links inside it. Some of the URLs contain older version numbers. For example, if you use the breadcrumbs at the top, things can get confusing as the latest version shows as v1.3.0 which has different C++ syntax due to the latest changes in eosio.cdt )Contract Development Toolkit) https://developers.eos.io/eosio-cpp/v1.3.0/docs/introduction-to-smart-contracts

Environment Setup

@justinjmoses
justinjmoses / Deferred.js
Last active May 11, 2018
Migrating to jQuery 3 Promises A+
View Deferred.js
module.exports = class Deferred {
constructor() {
this._promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
}
resolve(value) {
this._resolve(value);
You can’t perform that action at this time.