Skip to content

Instantly share code, notes, and snippets.

View hayesgm's full-sized avatar

Geoff Hayes hayesgm

View GitHub Profile
QmSwPdeQcqfJ8w6eBUo8UcW4s2jk9ZRKGQ8t29WpL8Zukv
@hayesgm
hayesgm / download.js
Last active March 4, 2021 07:23
Download File JS (No Deps)
const fs = require('fs').promises;
const path = require('path');
const http = require('http');
const https = require('https');
const { URL } = require('url');
function getOptions(url) {
let u = new URL(url);
return {
host: u.hostname,
@hayesgm
hayesgm / flat.js
Last active September 9, 2020 20:16
#!env node
let path = require('path');
let fs = require('fs').promises;
async function run(build, contract) {
let buildJson = JSON.parse(await fs.readFile(build, 'utf8'));
let contracts = buildJson['contracts'];
pragma solidity ^0.6.8;
interface Comptroller {
function getCompAddress() external view returns (address);
function claimComp(address holder) external;
function transfer(address dst, uint256 amount) external returns (bool success);
}
interface Erc20 {
function symbol() external returns (string memory);
let Eth = {
read: (network, contract, fn, args, ethers=require('ethers')) =>
Object.entries(
new ethers.Contract(
contract,
[fn],
new ethers.providers.InfuraProvider(network)
).functions
)[0][1](...args),
write: (network, contract, fn, args, pk=process.env('ethereum'), ethers=require('ethers')) =>

Overview

To understand how constructors through Solidity works (that is, how do we go from the compiled contract's bin to a live deployed contract with a different deployedBytecode), I took a deep dive into how one simple contract worked.

The contract Simple.sol:

pragma solidity ^0.5.12;

contract Simple {
@hayesgm
hayesgm / FaucetTokenABI.json
Last active February 16, 2018 22:11
Compound Faucet Token ABI
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
@hayesgm
hayesgm / PriceOracleABI.json
Created January 25, 2018 01:23
Compound Price Oracle ABI
[
{
"type": "function",
"stateMutability": "nonpayable",
"payable": false,
"outputs": [
{
"type": "bool",
"name": ""
}
@hayesgm
hayesgm / MoneyMarketABI.json
Last active May 18, 2018 20:42
Compound Money Market ABI
[
{
"constant": true,
"inputs": [],
"name": "maxLiquidationDiscountRateBPS",
"outputs": [
{
"name": "",
"type": "uint16"
}
@hayesgm
hayesgm / simple_block_loader.exs
Last active October 19, 2018 13:24
Simple Block Loader
# ETHEREUM_SCHEME=https ETHEREUM_HOST="ropsten.infura.io" ETHEREUM_PORT=443 iex -S mix
Application.put_env(EVM, :debugger, true)
EVM.Debugger.Breakpoint.init()
EVM.Debugger.Breakpoint.set_breakpoint(%EVM.Debugger.Breakpoint{conditions: [address: <<188, 31, 252, 22, 32, 218, 20, 104, 98, 74, 89, 108, 184, 65, 211, 94, 107, 47, 31, 182>>]})
load_hex = fn("0x" <> hex_string) ->
padded_hex_string = if rem(byte_size(hex_string), 2) == 1, do: "0" <> hex_string, else: hex_string
{:ok, hex} = Base.decode16(padded_hex_string, case: :lower)