Skip to content

Instantly share code, notes, and snippets.

:shipit:
What's happening?

Adrian Li adrianmcli

:shipit:
What's happening?
Block or report user

Report or block adrianmcli

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
@adrianmcli
adrianmcli / web3_error_log.txt
Created Nov 5, 2019
Error log from Web3.js install on Node v13
View web3_error_log.txt
> keccak@1.4.0 install /Users/adrianli/dev/temp/node_modules/keccak
> npm run rebuild || echo "Keccak bindings compilation fail. Pure JS implementation will be used."
> keccak@1.4.0 rebuild /Users/adrianli/dev/temp/node_modules/keccak
> node-gyp rebuild
CXX(target) Release/obj.target/keccak/src/addon.o
../src/addon.cc:37:47: error: too few arguments to function call, single argument 'context' was not specified
unsigned int rate = info[0]->IntegerValue();
@adrianmcli
adrianmcli / counter-composition.js
Last active Feb 5, 2019
An example of using plain functions and composing them to make state containers.
View counter-composition.js
// state container definition
const useState = initVal => {
let val = initVal;
const get = () => val;
const set = x => (val = x);
return Object.freeze({ get, set });
};
@adrianmcli
adrianmcli / counter.js
Created Jan 6, 2019
Example of encapsulating state with a function that return objects.
View counter.js
const makeCounter = (initVal = 0) => {
let count = initVal;
const get = () => count;
const set = x => (count = x);
const inc = () => count++;
const dec = () => count--;
return Object.freeze({
get,
@adrianmcli
adrianmcli / compile.js
Last active Jan 14, 2020
Programmatically compile and deploy Solidity smart contracts for your tests
View compile.js
const path = require("path");
const fs = require("fs");
const TruffleCompile = require("truffle-compile");
// Promisify truffle-compile
const truffleCompile = (...args) =>
new Promise(resolve => TruffleCompile(...args, (_, data) => resolve(data)));
const compile = async filename => {
const sourcePath = path.join(__dirname, "../contracts", filename);
View helpers.js
const Web3 = require("web3") // import web3 v1.0 constructor
// use globally injected web3 to find the currentProvider and wrap with web3 v1.0
const getWeb3 = () => {
const myWeb3 = new Web3(web3.currentProvider)
return myWeb3
}
// assumes passed-in web3 is v1.0 and creates a function to receive contract name
const getContractInstance = (web3) => (contractName) => {
View newTests.js
const { getWeb3, getContractInstance } = require("./helpers")
const web3 = getWeb3()
const getInstance = getContractInstance(web3)
contract("Counter", (accounts) => {
it("should initialize with a count of 0", async () => {
const counter = getInstance("Counter")
const count = await counter.methods.get().call()
const expected = 0
View oldTests.js
const Counter = artifacts.require("Counter")
contract("Counter", (accounts) => {
it("should initialize with a count of 0", async () => {
const counter = await Counter.deployed()
const count = await counter.get.call()
const expected = 0
assert.equal(count, expected, "count was not initialized with 0")
@adrianmcli
adrianmcli / output.txt
Last active May 22, 2018
script for tracking network requests from a website
View output.txt
https://www.googletagservices.com/tag/js/gpt.js
https://www.googletagmanager.com/gtm.js?id=GTM-MNVXW26
https://c.amazon-adsystem.com/aax2/apstag.js
https://ap.lijit.com/rtb/bid?src=prebid_prebid_0.34.0
https://coinmarketcap-d.openx.net/w/1.0/arj?ju=https%3A%2F%2Fcoinmarketcap.com%2F&jr=https%3A%2F%2Fcoinmarketcap.com%2F&ch=UTF-8&res=1366x768x24&ifr=false&tz=-540&tws=800x600&ef=bt%252Cdb&be=1&bc=hb_pb_2.0.0&nocache=1526994145454&auid=539181151%2C539181149&dddid=0127ceee-84dd-4e77-8998-28605400c347%2C0624d006-e24f-4dc6-b4c5-80f14ae24698&aus=160x600%7C728x90&
https://as-sec.casalemedia.com/cygnus?v=7&fn=cygnus_index_parse_res&s=219064&r=%7B%22id%22%3A%2274103715%22%2C%22site%22%3A%7B%22page%22%3A%22https%3A%2F%2Fcoinmarketcap.com%2F%22%7D%2C%22imp%22%3A%5B%7B%22id%22%3A%221%22%2C%20%22banner%22%3A%7B%22w%22%3A728%2C%22h%22%3A90%2C%22topframe%22%3A1%7D%2C%22ext%22%3A%20%7B%22sid%22%3A%221_1%22%2C%22siteID%22%3A219064%7D%7D%2C%7B%22id%22%3A%222%22%2C%20%22banner%22%3A%7B%22w%22%3A160%2C%22h%22%3A600%2C%22topframe%
@adrianmcli
adrianmcli / transform.js
Last active May 9, 2018
just a simple function to transform a typical 0x order object into the form we need.
View transform.js
const transform = ({
exchangeContract,
expiration,
feeRecipient,
salt,
maker,
taker
}) => ({
exchangeContractAddress: exchangeContract,
expirationUnixTimestampSec: expiration,
@adrianmcli
adrianmcli / EXAMPLES.md
Last active Feb 21, 2018
Concrete use-case examples for b0x.network.
View EXAMPLES.md

Examples

Please note that WETH and ETH will be used interchangeably in the following discussion.

The b0x network allows anyone with ERC20 tokens to loan it out for interest on a margin trading platform.

Example 1: Alice holds a lot of ETH tokens and instead of letting it sit, she wants to lend it to traders who are looking to borrow money so that they can trade on margin. Alice creates a b0x order specifying the type of token she is lending out (i.e. loanToken) and the type of token that she wants the interest to be paid in (i.e. interestToken).

The lender can specify the specific margin amounts that the borrower must have in order to fill the order and maintain the loan.

You can’t perform that action at this time.