Skip to content

Instantly share code, notes, and snippets.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract CompileVsRuntime {
uint256 public constant j0 = ((7 / 11 + 3 / 13) * 22 + 1) * 39;
function foo(uint256 x, uint256 y, uint256 w, uint256 z, uint256 x2, uint256 y2, uint256 w2) external pure returns (uint256) {
uint256 j1 = ((x / y + z / w) * x2 + y2) * w2;
return j1;
}
@PaulRBerg
PaulRBerg / Mulmod.sol
Created March 17, 2021 09:52
Basic contract written in Solidity v0.8.2
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Mulmod {
uint256 public constant a = 2**254;
uint256 public constant b = 2**255;
function doMul(uint256 x, uint256 y) external pure returns (uint256) {
return x * y;
@PaulRBerg
PaulRBerg / liquidator.rs
Last active January 15, 2021 13:55
Source code for StackOverflow question
//! Liquidator Module
//!
//! This module is responsible for triggering liquidations.
use crate::{escalator::GeometricGasPrice, vault::Vault, HifiResult};
use ethers::{
core::abi::{self, Tokenize},
prelude::*,
};
use hifi_liquidator_bindings::{FyToken, UniswapV2Pair};
@PaulRBerg
PaulRBerg / generate-dsproxy-calldata.js
Created December 2, 2020 22:03
Generate DSProxy calldata
const ethers = require("ethers");
const DSProxyAbi = require("../abis/DSProxy.json");
const TargetContractAbi = require("../abis/TargetContract.json");
const defaultProvider = ethers.getDefaultProvider("kovan");
const dsProxyAddress = "0xa92Bed719071A4d33B0B348513E7e866a6ff6B3F";
const dsProxy = new ethers.Contract(dsProxyAddress, DSProxyAbi, defaultProvider);
const targetContractAddress = "0xE3CD2e7a628b57d3e50c5f7B921182f676721bDF";
const targetContract = new ethers.Contract(targetContractAddress, TargetContractAbi, defaultProvider);
This post links my 3Box profile to my Github account! Web3 social profiles by 3Box.
✅ did:3:bafyreibj65scex56egywsjogkoymcirx4epjlrpwlzmwuqbkgy3toyxe6y ✅
Create your profile today to start building social connection and trust online at https://3Box.io/
@PaulRBerg
PaulRBerg / typechain-v4-error.txt
Created November 9, 2020 11:58
TypeChain v4 error in solidity-template repo
Compiling...
Compiled 2 contracts successfully
Creating TypeChain artifacts in directory typechain for target ethers-v5
An unexpected error occurred:
SyntaxError: '=' expected. (8:15)
6 | import { Contract, ContractFactory, Overrides } from "@ethersproject/contracts";
7 |
> 8 | import type { Greeter } from "./Greeter";
| ^
@PaulRBerg
PaulRBerg / machine.js
Last active September 28, 2020 16:57
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@PaulRBerg
PaulRBerg / CarefulMath.sol
Created August 14, 2020 21:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.10+commit.00c0fcaf.js&optimize=true&gist=
/* SPDX-License-Identifier: LGPL-3.0-or-later */
pragma solidity ^0.6.10;
/**
* @title CarefulMath
* @author Compound
* @notice Exponential module for storing fixed-precision decimals.
* @dev Derived from OpenZeppelin's SafeMath library
*/
abstract contract CarefulMath {
@PaulRBerg
PaulRBerg / testotron.ts
Created August 13, 2020 19:09
Logging block timestamps
import { BigNumber } from "@ethersproject/bignumber";
import { Signer } from "@ethersproject/abstract-signer";
import { waffle } from "@nomiclabs/buidler";
import { expect } from "chai";
export function shouldBehaveLikeGreeter(_signers: Signer[]): void {
describe("1st Block", function () {
beforeEach(async function () {
await waffle.provider.send("evm_setNextBlockTimestamp", [1597348800]);
const blockTimestamp: BigNumber = await this.testotron.getBlockTimestamp();
@PaulRBerg
PaulRBerg / augmentations.d.ts
Created July 29, 2020 17:15
Augmenting the Context type used by Mocha in beforeEach, it, etc.
import { Erc20 } from "../typechain/Erc20";
declare module "mocha" {
export interface Context {
token: Token;
}
}