This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Task<T> = () => Promise<T>; | |
const tasks: Task<number>[] = [ | |
() => new Promise((resolve) => setTimeout(() => resolve(1), 1000)), | |
() => new Promise((resolve) => setTimeout(() => resolve(2), 2000)), | |
() => new Promise((resolve) => setTimeout(() => resolve(3), 1000)), | |
() => new Promise((resolve) => setTimeout(() => resolve(4), 3000)), | |
() => new Promise((resolve) => setTimeout(() => resolve(5), 1000)), | |
() => new Promise((resolve) => setTimeout(() => resolve(6), 2000)), | |
() => new Promise((resolve) => setTimeout(() => resolve(7), 2000)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rlp = require("rlp"); | |
const web3Utils = require("web3-utils"); | |
/** | |
* Calculates address of contract created by deployerAddr if CREATE is used (not CREATE2) | |
**/ | |
const calcAddress = (deployerAddr, nonce) => { | |
const rlpEncoded = Buffer.from(rlp.encode([deployerAddr, nonce])).toString('hex'); | |
const address = '0x' + web3Utils.sha3('0x' + rlpEncoded).substr(66 - 40); | |
return address; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SECONDS_PER_YEAR = 365.25 * 24 * 60 * 60; | |
const BLOCKS_IN_A_YEAR = SECONDS_PER_YEAR / 14; | |
/** | |
* Formula source: http://www.linked8.com/blog/158-apy-to-apr-and-apr-to-apy-calculation-methodologies | |
* | |
* @param interest {Number} APY as percentage (ie. 6) | |
* @param frequency {Number} Compounding frequency (times a year) | |
* @returns {Number} APR as percentage (ie. 5.82 for APY of 6%) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disclamer: | |
// We are assuming [email protected] is instantiated with a MetaMask provider or similar | |
const yourAccount = (await web3.eth.getAccounts())[0].toLowerCase() | |
function namehash(name) { | |
var node = '0x0000000000000000000000000000000000000000000000000000000000000000'; | |
if (name !== '') { | |
var labels = name.split("."); | |
for(var i = labels.length - 1; i >= 0; i--) { |