Skip to content

Instantly share code, notes, and snippets.

View gregorynicholas's full-sized avatar
💀
alter.

gregory nicholas gregorynicholas

💀
alter.
View GitHub Profile
@gregorynicholas
gregorynicholas / redirects-in-react-router-v6.md
Created October 17, 2021 20:08 — forked from mjackson/redirects-in-react-router-v6.md
Notes on handling redirects in React Router v6, including a detailed explanation of how this improves on what we used to do in v4 and v5

Redirects in React Router v6

An important part of "routing" is handling redirects. Redirects usually happen when you want to preserve an old link and send all the traffic bound for that destination to some new URL so you don't end up with broken links.

The way we recommend handling redirects has changed in React Router v6. This document explains why.

Background

In React Router v4/5 (they have the same API, you can read about why we had to bump the major version here) we had a <Redirect> component that you could use to tell the router when to automatically redirect to another URL. You might have used it like this:

@gregorynicholas
gregorynicholas / wallets_fee_neo3.json
Created September 17, 2021 00:07 — forked from pitersky/wallets_fee_neo3.json
wallets_fee_neo3.json
[
{
"className": "ARKCoin",
"txWebUrl": "https://explorer.ark.io/transaction/",
"feeData": {
"fee": "10000000"
},
"explorers": [
{
"className": "ArkExplorer",
@gregorynicholas
gregorynicholas / whitepapers.tsv
Created September 17, 2021 00:03 — forked from blockchainvc/whitepapers.tsv
WHITEPAPERS: Smart Contract Protocols
Name Link Whitepaper title
Achain (previously thinkyoung) https://www.achain.com/Achain%20Whitepaper%202.0_EN.pdf Achain Blockchain Whitepaper: build to be boundless
Aergo (by blocko) https://www.aergo.io/paper/ multiple
Aion https://aion.network/media/en-aion-network-technical-introduction.pdf Aion: enabling the decentralized Internet
Ark https://ark.io/Whitepaper.pdf A Platform for Consumer Adoption
Avalanche https://ipfs.io/ipfs/QmUy4jh5mGNZvLkjies1RWM4YuvJh5o2FYopNPVYwrRVGV Snowflake to Avalanche: a novel metastable consensus protocol family for cryptocurrencies
Blink https://blink.network/media/blink-protocol.pdf Proof-of-stake distrbuted consensus protocol
Byteball https://byteball.org/Byteball.pdf A Decentralized System for Storage and Transfer of Value
Cardano https://whitepaperdatabase.com/cardano-ada-whitepaper/ Ouroboros: A provably secure proof-of-stake blockchain protocol
Celer Network https://www.celer.network/doc/CelerNetwork-Whitepaper.pdf Celer Network: Bring Internet Scale to Every Blockchai
@gregorynicholas
gregorynicholas / deploy.js
Created November 8, 2020 18:23 — forked from ajb413/deploy.js
A Node.js script for deploying a smart contract to the locally hosted Ethereum instance.
const fs = require('fs');
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');
const bytecode = fs.readFileSync('./build/FirstContract.bin');
const abi = JSON.parse(fs.readFileSync('./build/FirstContract.abi'));
(async function () {
const ganacheAccounts = await web3.eth.getAccounts();
const myWalletAddress = ganacheAccounts[0];
@gregorynicholas
gregorynicholas / getCompApy.js
Created November 8, 2020 18:21
Get COMP APY for USDT. Uses Node.js with Compound.js. Be sure to fill in your Infura project ID at the top. See comments for run instructions.
const Compound = require('@compound-finance/compound-js');
const provider = 'https://mainnet.infura.io/v3/<YOUR INFURA API KEY HERE>';
const cTokenToGetCompApy = Compound.cUSDT;
const underlying = cTokenToGetCompApy.slice(1, 10);
const underlyingDecimals = Compound.decimals[underlying];
const cTokenDecimals = 8; // always 8
const comptroller = Compound.util.getAddress(Compound.Comptroller);
const opf = Compound.util.getAddress(Compound.PriceFeed);
@gregorynicholas
gregorynicholas / getCompAccrued.js
Created November 8, 2020 18:19 — forked from ajb413/getCompAccrued.js
Get COMP accrued for an account on mainnet using Compound.js (https://github.com/compound-finance/compound-js)
const Compound = require('@compound-finance/compound-js');
const provider = 'https://mainnet.infura.io/v3/' + process.env.infuraApiKey;
// mainnet
const CompoundLens = Compound.util.getAddress(Compound.CompoundLens);
const LensAbi = Compound.util.getAbi(Compound.CompoundLens);
const COMP = Compound.util.getAddress(Compound.COMP);
const Comptroller = Compound.util.getAddress(Compound.Comptroller);
const me = '0xa0df350d2637096571F7A701CBc1C5fdE30dF76A';
@gregorynicholas
gregorynicholas / minte-usdc.js
Created November 8, 2020 18:16 — forked from ajb413/minte-usdc.js
Local host fork of mainnet, "steal" some test USDC from a whale (cUSDC contract).
// First run Ganache locally with `cUsdc` address unlocked
const Web3 = require('web3');
const web3 = new Web3('http://127.0.0.1:8545');
const usdcAbi = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"authorizer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"nonce","type":"bytes32"}],"name":"AuthorizationCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"authorizer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"nonce","type":"bytes32"}],"name":"AuthorizationUsed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_account","type":"address"}],"name":"Blacklist
@gregorynicholas
gregorynicholas / comp_earned.md
Created November 8, 2020 18:15 — forked from ajb413/comp_earned.md
How do I retrieve the "COMP earned" value from the Compound protocol? Get the amount of accrued COMP token for an address using the Ethereum blockchain.

How do I retrieve the "COMP earned" value?

With a Smart Contract or JSON RPC

Get the value of COMP earned for an address that uses the Compound protocol. This can be done using the Lens contract with JSON RPC or another Smart Contract. If you do an eth_call with JSON RPC, it is free (no gas costs).

  1. Use the getCompBalanceMetadataExt method in the Lens contract https://etherscan.io/address/0xd513d22422a3062Bd342Ae374b4b9c20E0a9a074#code
  2. Lens address is posted here https://github.com/compound-finance/compound-protocol/blob/master/networks/mainnet.json#L11
  3. Here is the definition https://github.com/compound-finance/compound-protocol/blob/master/contracts/Lens/CompoundLens.sol#L278
@gregorynicholas
gregorynicholas / Get_COMP_APY.md
Created November 8, 2020 18:14 — forked from ajb413/Get_COMP_APY.md
Finding the COMP APY