Skip to content

Instantly share code, notes, and snippets.

View darkerego's full-sized avatar

Darkerego darkerego

View GitHub Profile
@darkerego
darkerego / MinimalistERC20.sol
Created November 4, 2024 03:44
A minimalist ERC20 token size optimized for low deployment costs.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
abstract contract MinimalistErc20 {
address public owner;
string public name;
string public symbol;
uint256 public totalSupply;
uint8 immutable public decimals;
mapping (address => uint256) public balanceOf;
#!/bin/bash
# Get the total memory in kilobytes
TOTAL_MEM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
# Calculate half of the total memory
HALF_MEM_KB=$((TOTAL_MEM_KB / 2))
# Convert kilobytes to megabytes (MB)
HALF_MEM_MB=$((HALF_MEM_KB / 1024))
@darkerego
darkerego / test_particle_async_ws.py
Created May 27, 2024 07:54
Using AsyncWeb3 with trio in python
import os
import dotenv
import trio
import trio_asyncio
from web3 import AsyncWeb3
from web3 import WebsocketProviderV2
dotenv.load_dotenv()
@darkerego
darkerego / simulation.py
Created April 9, 2024 18:55
simulation
import numpy as np
import rebound
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def add_galactic_potential(sim, mass_distribution):
"""
Simplified function to simulate the galactic potential effect on the simulation.
This function modifies the velocities of particles to simulate a basic galactic potential.
#! /bin/bash
# Modified to run both (redudantly, yes, I know, I am paranoid, you should be too) checks
#
set -eu
# find path to liblzma used by sshd
path="$(ldd $(which sshd) | grep liblzma | grep -o '/[^ ]*')"
echo 'Check one: does it even exist?'
# does it even exist?
if [ "$path" == "" ]
@darkerego
darkerego / equalizer_flash_loan.sol
Last active December 6, 2023 04:11
equalizer flash loan
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
interface IERC20 {
function approve(address spender, uint256 amount) external returns (bool);
}
interface IERC3156FlashBorrower {
function onFlashLoan(
address initiator,
@darkerego
darkerego / uniswap-v3-example.sol
Created September 6, 2023 13:04 — forked from mempirate/uniswap-v3-example.sol
Simple example on how to swap on UniswapV3 with the SwapRouter
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
pragma abicoder v2;
import "@uniswap/v2-periphery/contracts/interfaces/IWETH.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
@darkerego
darkerego / gist:edce02f936b6441b93e3ca66ae817780
Last active September 1, 2023 22:00
Attempting to Revert Static Calls
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TestStateChange {
uint public originalValue = 123;
uint public oldValue;
uint public incrementer = 0;
bytes4 public constant CHANGE_SEL = bytes4(keccak256(bytes('changeState(uint256)')));
bytes4 public constant WRAP_CHANGE_SEL = bytes4(keccak256(bytes('wrapChangeState(uint256)')));
error CallFailedError(string reason,address msgSender,address txOrigin);
@darkerego
darkerego / test_call.sol
Last active August 8, 2023 21:34
Solidity Assembly Call & Get Return Data / Revert with Reason
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2
contract TestExec {
address owner;
constructor() {
owner = msg.sender;
}
@darkerego
darkerego / ahttp_client.py
Last active July 30, 2023 23:50
AioHttp Client Skeleton Class
import asyncio
import json
import aiohttp
class AsyncHttpClient:
def __init__(self, _headers=None, base_url: str = None, timeout: (int, float) = 60):
"""
A skeletal asynchronous HTTP class. Because I found myself writing this same code