Skip to content

Instantly share code, notes, and snippets.

@Philogy
Philogy / GolfBounty.sol
Last active March 15, 2024 02:38
Curta Golf Bounty Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ICurtaGolf} from "curta-golf/src/interfaces/ICurtaGolf.sol";
import {ICourse} from "curta-golf/src/interfaces/ICourse.sol";
import {IERC721} from "./interfaces/IERC721.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
/// @author philogy <https://github.com/philogy>
@Philogy
Philogy / uniswap-v3-fees.py
Created January 17, 2024 20:05
Very simple model of Uniswap V3 Fees
from attrs import define
@define
class Tick:
fee_growth_outside: int
def cross(self, fee_growth_global: int):
self.fee_growth_outside = fee_growth_global - self.fee_growth_outside
@Philogy
Philogy / Broken.s.sol
Created January 16, 2024 21:25
Unable to deploy because of simulation script
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {Script} from "forge-std/Script.sol";
import {Test} from "forge-std/Test.sol";
import {console2 as console} from "forge-std/console2.sol";
contract Counter {
uint256 public count;
(defn _double [:uint256 x] :uint256 [:internal :pure]
(* x 2))
(defn add [:uint256 x] :uint256 [:external :pure]
(if (< x 10) 0 (self/_double x)))
@Philogy
Philogy / NFT_ERC6909.sol
Created January 6, 2024 11:29
EIP6909 Implementation optimized for IDs with a totalSuppy of 1 each (collection of purely non-fungible tokens
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple EIP-6909 for IDs that are solely non-fungible.
/// @author Forked from Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC6909.sol)
/// @author philogy <https://github.com/philogy>
///
/// @dev Note:
/// The ERC6909 standard allows minting and transferring to and from the zero address,
/// minting and transferring zero tokens, as well as self-approvals.
@Philogy
Philogy / Proxy.sol
Created December 16, 2023 01:24
No Assembly Solidity ERC1967 Proxy
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
/// @author philogy <https://github.com/philogy>
contract Proxy {
uint256 internal constant IMPL_SLOT = uint256(keccak256("eip1967.proxy.implementation")) - 1;
uint256 internal constant ADMIN_SLOT = uint256(keccak256("eip1967.proxy.admin")) - 1;
address[0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff] internal slots;
@Philogy
Philogy / main.rs
Created December 4, 2023 16:17
LeetCode: Queue from 2-Stacks in Rust
struct MyQueue {
queue: Vec<i32>,
stack: Vec<i32>,
}
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl MyQueue {
@Philogy
Philogy / frange.py
Created August 17, 2023 09:58
Python `range` but with float starts, ends and steps
def frange(start, end=None, step=None):
assert (end is None) <= (step is None)
if end is None:
start, end, step = 0, start, 1
elif step is None:
step = 1
assert step != 0
sign = -1 if step < 0 else 1
v = start
while v * sign < end * sign:
@Philogy
Philogy / day2.rs
Last active June 26, 2023 20:16
Advent of Code 2022 (Day 2) in Rust
use std::cmp::{Ordering, PartialOrd};
use std::fs;
#[derive(Debug, PartialEq, Eq, Clone)]
enum Move {
Rock,
Paper,
Scissors,
}
@Philogy
Philogy / day1.rs
Last active June 25, 2023 21:58
Advent Of Code 2022 (Day 1) in Rust
use std::fs;
fn sort_desc<T: Ord>(v: &mut Vec<T>) {
v.sort_by(|a, b| b.cmp(a));
}
/// # Advent Of Code 2022 (Day 1).
///
/// Challenge is you an input which displays "calories of elves" ([link](https://adventofcode.com/2022/day/1)):
///