Skip to content

Instantly share code, notes, and snippets.

View riordant's full-sized avatar
💯

tadhg riordant

💯
View GitHub Profile
@riordant
riordant / geth-dev-mode.sh
Last active November 29, 2021 09:50
Geth Gananche emulator - set up Geth like Ganache. Geth produces better debugging output for Remix and Truffle Debug.
# cd ~/.geth/
# Add following script here
# Create ~/.geth/keys, ~/geth/dev
# Add keys 0.txt,1.txt..N.txt, and passwords.txt, with each line in passwords.txt representing password for that account
# import into ~/geth/dev: geth account import --datadir ~/.geth/chain ~/.geth/dev/0.txt etc., enter same password
@riordant
riordant / DSMath-ethers.js
Created February 8, 2021 16:24
ethers DSMath - perform decimal precision operations with ethers BigNumber. Adapted from Solidity DSMath library.
const { ethers } = require("ethers");
BigNumber = ethers.BigNumber
module.exports = {
WAD: ethers.utils.parseUnits('1'),
//rounds to zero if x*y < WAD / 2
wmul: function(x, y) {
return x.mul(y).add(WAD.div(2)).div(WAD);
},
@riordant
riordant / etherscan-get-multifile.py
Created December 16, 2021 08:56
Download a multifile-verified contract from Etherscan as a simple flattened contract.
from etherscan import Etherscan
import os
import json
from time import sleep
# setup
ethscan = Etherscan('YOUR_API_KEY_HERE')
# NOTE: must be a multi-verified contract to work. Staked Aave used as example here
address = "0x4da27a545c0c5b758a6ba100e3a049001de870f5"
@riordant
riordant / test-fork.ts
Created December 22, 2021 09:02
Separate Hardhat task to run tests on mainnet fork
import {task, types} from "hardhat/config";
task("test-fork", "Runs mocha tests on a fork of mainnet").addOptionalParam(
"url",
"The URL of the Mainnet archive node",
"",
types.string
).setAction(async (taskArgs, hre) => {
hre.config.networks.hardhat.forking = {
url: taskArgs.url,
@riordant
riordant / get_inner_struct_mapping.ts
Last active March 22, 2022 07:03
Retrieve the storage slot value of a (mapping => Struct) -> (mapping => uint) in Solidity.
/*
architecture is like so:
Struct struct {
...
mapping(address => uint) map;
...
}
contract X {
@riordant
riordant / hardhat-artifact-to-inteface.sh
Created March 28, 2022 09:45
Converts a hardhat artifact JSON file to an interface from CLI. Useful for compiled contracts that you don't have an interface file for.
# requirements:
# jq
# abi2solidity
cat Contract.json | jq '.abi' > Contract.abi.json
abi2solidity -i Contract.abi.json -o IContract.sol
@riordant
riordant / get_solc_versions.sh
Created October 3, 2022 09:03
Download all Solidity Linux versions, make executable, and organize into folders based on version name.
#!/bin/bash
# will skip already created folders, just need to prepend new version names.
versions=(0.8.17 0.8.16 0.8.15 0.8.14 0.8.13 0.8.12 0.8.11 0.8.10 0.8.9 0.8.8 0.8.7 0.8.6 0.8.5 0.8.4 0.8.3 0.8.2 0.8.1 0.8.0 0.7.6 0.7.5 0.7.4 0.7.3 0.7.2 0.7.1 0.7.0 0.6.12 0.6.11 0.6.10 0.6.9 0.6.8 0.6.7 0.6.6 0.6.5 0.6.4 0.6.3 0.6.2 0.6.1 0.6.0 0.5.17 0.5.16 0.5.15 0.5.14 0.5.13 0.5.12 0.5.11 0.5.10 0.5.9 0.5.8 0.5.7 0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.26 0.4.25 0.4.24 0.4.23 0.4.22 0.4.21 0.4.20 0.4.19 0.4.18 0.4.17 0.4.16 0.4.15 0.4.14 0.4.13 0.4.12 0.4.11 0.4.10)
for i in "${versions[@]}"
do
mkdir $i && cd $i && wget https://github.com/ethereum/solidity/releases/download/v$i/solc-static-linux && mv solc-static-linux solc && chmod +x solc && cd ..
done
@riordant
riordant / set_balance_arbitrum.sh
Created February 22, 2023 17:18
Set Balance of the 3 major stables (DAI, USDT, USDC) on Arbitrum forked node, via Anvil/HH setStorageAt.
import { ethers } from "ethers";
async function setBalance(account: string, token: string, slot: number){
const paddedSlot = ethers.utils.hexZeroPad(ethers.utils.hexlify(slot), 32);
const paddedKey = ethers.utils.hexZeroPad(account, 32);
const itemSlot = ethers.utils.keccak256(paddedKey + paddedSlot.slice(2));
const storageSlot = ethers.utils.hexStripZeros(itemSlot);
await ethers.provider.send("anvil_setStorageAt", [
token,
storageSlot,
@riordant
riordant / get-addresses-ledger.ts
Created February 24, 2023 15:33
Get the PATH master viewing key from a USB-connected Ledger device opened in the Ethereum app, use this to acquire all the child addresses in this path within the defined RANGE.
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
import Eth from "@ledgerhq/hw-app-eth";
import BIP32Factory from 'bip32';
import * as ecc from 'tiny-secp256k1';
import publicKeyToAddress from 'ethereum-public-key-to-address';
const bip32 = BIP32Factory(ecc);
const PATH = "44'/60'/0'";
const RANGE = 10;
@riordant
riordant / hexens_convexstfrxeth_followup.md
Created February 2, 2024 09:57
Hexens Audit: ConvexStFrxEthStrategy: Follow Up

SPOOL2-2 - DISCREPANCIES IN _REDEEMFROMPROTOCOL FUNCTION IMPLEMENTATION

  • Commit: https://github.com/SpoolFi/spool-v2-core/commit/86065428a4d5e6de3c7b10909db532033c578c80

  • Description:

    • Acknowledged, implemented in the commit hash above.

    • the _redeemFromProtocol() function now uses just one slippage value, for the output WETH amount. We pass an empty array to redeem inner for the slippages, as we assume that we will catch any issues on the output WETH amount. We must allow passing slippages to _redeemInner, as in the emergencyWithdraw function, we will just get back stETH and frxETH and send to the emergency recipient, and so we still want to use slippages for stETH and frxETH in this case. I've updated the redeemFast/emergencyWithdraw description, to better relate this.

    • In this commit, I have also included some event emissions that we missed:

  • in assetGroupWrap, we return a ratio array, which represents the amounts of stETH/frxETH that's used as input t