Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
PaulRBerg / getRandomEthereumAddress.ts
Last active September 2, 2021 20:07
Random Ethereum address generator written in TypeScript
export function getRandomEthereumAddress(): string {
const length: number = 40;
const number: string = [...Array(length)]
.map(() => {
return Math.floor(Math.random() * 16).toString(16);
})
.join("");
return "0x" + number;
}
@PaulRBerg
PaulRBerg / sablier-v1.1-streams.graphql
Created August 19, 2021 22:32
GraphQL query for getting the Sablier v1.1 streams created by a given sender
{
streams(where: { sender: "ADDRESS_HERE"}) {
id
deposit
cancellation {
id
recipientBalance
senderBalance
}
recipient
@PaulRBerg
PaulRBerg / IErc20.d.ts
Created August 13, 2021 14:01
Incorrect TypeChain bindings for IErc20.d.ts
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import {
ethers,
EventFilter,
Signer,
BigNumber,
BigNumberish,
@PaulRBerg
PaulRBerg / typechain-index.ts
Created August 12, 2021 10:10
Example for a "typechain/index.ts" file
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
export type { IOwnable } from "./IOwnable";
export type { Ownable } from "./Ownable";
export type { Erc20 } from "./Erc20";
export type { Erc20Permit } from "./Erc20Permit";
export type { Erc20Recover } from "./Erc20Recover";
export type { IErc20 } from "./IErc20";
export type { IErc20Permit } from "./IErc20Permit";
@PaulRBerg
PaulRBerg / HifiProxyTarget.abi.json
Created August 6, 2021 12:47
ABI for HifiProxyTarget (with the `depositCollateralAndBorrowHTokenAndAddLiquidity` function)
[
{
"inputs": [
{
"internalType": "address",
"name": "target",
"type": "address"
}
],
"name": "CallToNonContract",
YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT No package manager detected; defaulting to Yarn
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT ➤ YN0000: LICENSE
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT ➤ YN0000: index.js
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT ➤ YN0000: package.json
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT ➤ YN0000: readme.md
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT ➤ YN0000: Package archive generated in /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668/package.tgz
➤ YN0000: │ /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/xfs-d4fad668 STDOUT ➤ YN0000: Done in 0s 46ms
➤ YN0000: │ /private/v
@PaulRBerg
PaulRBerg / PRBMathUD60x18Consumer.sol
Last active March 22, 2022 15:00
Example consumer contract for PRBMathUD60x18 library: https://github.com/paulrberg/prb-math
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "@prb/math/contracts/PRBMathUD60x18.sol";
contract UnsignedConsumer {
using PRBMathUD60x18 for uint256;
/// @notice Calculates x*1e18÷y while handling possible intermediary overflow.
function unsignedDiv(uint256 x, uint256 y) external pure returns (uint256 result) {
@PaulRBerg
PaulRBerg / prepare-package.ts
Last active July 16, 2021 12:09
Hardhat script for generating npm-ready folders for your contracts and typechain artifacts (with ethers-v5 as the target). Copied from https://github.com/hifi-finance/hifi-protocol/blob/2230a41269097c10183a0d72683345fe3a256f18/scripts/prepare-package.ts
import path from "path";
import fsExtra from "fs-extra";
import hre from "hardhat";
import { Artifact } from "hardhat/types";
const artifactsDir: string = path.join(__dirname, "..", "artifacts");
const contracts: string[] = [
"Admin",
"AdminInterface",
@PaulRBerg
PaulRBerg / PowerNumberFormQuestion.txt
Created April 6, 2021 12:20
I wanted to post this question on mathematica.stackexchange.com but I couldn't because of this error: "Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut"
Being in need of calculating the following numbers with 18 decimals of precision:
$$
2^{2^{-x}}, x\in{\mathbb{N}}
$$
I looked for what built-in symbols can help me and found [Power](https://reference.wolfram.com/language/ref/Power.html) and [NumberForm](https://reference.wolfram.com/language/ref/NumberForm.html). I tried an example:
```mathematica
NumberForm[Power[2, 2^-3], 18]
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(
uint256 a,
uint256 b,
uint256 denominator