Skip to content

Instantly share code, notes, and snippets.

View joejordan's full-sized avatar

Joe Jordan joejordan

View GitHub Profile
@joejordan
joejordan / gist:69eb91eb03ec9a3dbd3c06dbd2a19d09
Created January 17, 2018 20:09
Efficient way to compute the exponentiation of a fraction and an integer
// https://ethereum.stackexchange.com/a/10432/24989
// Approximate solution using the binomial expansion
// The following is a decent, low-cost approximation:
// Computes `k * (1+1/q) ^ N`, with precision `p`. The higher
// the precision, the higher the gas cost. It should be
// something around the log of `n`. When `p == n`, the
// precision is absolute (sans possible integer overflows). <edit: NOT true, see comments>
// Much smaller values are sufficient to get a great approximation.
function fracExp(uint k, uint q, uint n, uint p) returns (uint) {
ℹ This is the configuration for your development deployment:
Ethereum Node: ws://localhost:8545
ENS registry: 0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1
APM registry: aragonpm.eth
DAO address: 0xE9866fE6dF20F032E62Cc3094EdDe9748fE51753
Opening http://localhost:3000/#/0xE9866fE6dF20F032E62Cc3094EdDe9748fE51753 to view your DAO
(node:12216) UnhandledPromiseRejectionWarning: Error: Error: Command failed: npm run start:local
sh: 1: copy-aragon-ui-assets: not found
@joejordan
joejordan / FileUtils.sol
Created January 26, 2023 02:34
Foundry JSON troubles
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";
import { stdJson } from "forge-std/StdJson.sol";
contract FileUtils is Script {
using stdJson for string;
@joejordan
joejordan / seaportValidatorErrors.ts
Created June 23, 2023 20:15
Seaport Order Validator -- Convert SeaportValidator Errors and Warnings into a readable error message
/**
* Converts a SeaportValidator error/warning code to a human readable string
* @param code number indicating the error/warning code
* @returns readable string
*/
export function getErrorMessage(code: number): string {
switch (code) {
case 100:
return "Invalid order format. Ensure offer/consideration follow requirements";
case 200: