Skip to content

Instantly share code, notes, and snippets.

View charles-cooper's full-sized avatar

Charles Cooper charles-cooper

View GitHub Profile
@charles-cooper
charles-cooper / manager.vy
Created November 25, 2024 13:22
vyper stablecoin
# ported from https://github.com/shafu0x/MicroStable/blob/main/src/MicroStable.sol
from ethereum.ercs import IERC20
import micro_stable
interface Oracle:
def latest_answer() -> uint256: view
MIN_COLLAT_RATIO: public(constant(uint256)) = 15 * 10**17
@charles-cooper
charles-cooper / VaultV3.vy
Created November 24, 2024 19:25
sample yearn contract
from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed
# INTERFACES #
interface IStrategy:
def asset() -> address: view
def balanceOf(owner: address) -> uint256: view
def maxDeposit(receiver: address) -> uint256: view
def maxWithdraw(owner: address) -> uint256: view
@charles-cooper
charles-cooper / CurveStableSwapNG-0.4.1.vy
Created October 25, 2024 15:50
vyper compiler benchmark
## pragma optimize codesize
# pragma enable-decimals
"""
@title CurveStableSwapNG
@author Curve.Fi
@license Copyright (c) Curve.Fi, 2020-2023 - all rights reserved
@notice Stableswap implementation for up to 8 coins with no rehypothecation,
i.e. the AMM does not deposit tokens into other contracts. The Pool contract also
records exponential moving averages for coins relative to coin 0.
@dev Asset Types:
@charles-cooper
charles-cooper / CurveStableSwapNG-0.4.1.vy
Created October 7, 2024 16:45
sample vyper contract
## pragma optimize codesize
# pragma evm-version shanghai
# pragma enable-decimals
"""
@title CurveStableSwapNG
@author Curve.Fi
@license Copyright (c) Curve.Fi, 2020-2023 - all rights reserved
@notice Stableswap implementation for up to 8 coins with no rehypothecation,
i.e. the AMM does not deposit tokens into other contracts. The Pool contract also
records exponential moving averages for coins relative to coin 0.
2024-04-14T17:08:55.2635958Z Current runner version: '2.315.0'
2024-04-14T17:08:55.2663253Z ##[group]Operating System
2024-04-14T17:08:55.2663887Z Ubuntu
2024-04-14T17:08:55.2664206Z 22.04.4
2024-04-14T17:08:55.2664653Z LTS
2024-04-14T17:08:55.2664970Z ##[endgroup]
2024-04-14T17:08:55.2665360Z ##[group]Runner Image
2024-04-14T17:08:55.2665866Z Image: ubuntu-22.04
2024-04-14T17:08:55.2666266Z Version: 20240407.1.0
2024-04-14T17:08:55.2667230Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20240407.1/images/ubuntu/Ubuntu2204-Readme.md
@charles-cooper
charles-cooper / transient_benchmark.py
Created February 1, 2024 22:24
generate benchmarks for transient storage
#!/usr/bin/env python
with open("benchmark_control.easm", "w") as f:
print("PUSH1 251", file=f)
print("PUSH1 1", file=f)
for _ in range(10_000): # stay roughly within codesize limit, still large enough for benchmark
print("DUP2 MUL", file=f)
print("DUP1 DUP1 POP POP", file=f)
@charles-cooper
charles-cooper / module_example.vy
Last active January 13, 2024 15:11
more module examples
###
# access_control.vy
owner: address
def __init__():
self.owner = msg.sender
def check_owner():
assert msg.sender == self.owner
###
allowances: HashMap[address, HashMap[address, uint256]]
balanceOf: HashMap[address, uint256]
totalSupply: uint256
bundle: ERC20Bundle
def __init__():
... # do things with initializing and totalSupply
@external
@charles-cooper
charles-cooper / boa_asan.py
Last active January 16, 2024 14:36
address sanitizer
# usage:
# install asan fork of vyper 0.3.10 (`pip install git+https://github.com/charles-cooper/vyper@asan`)
# change `import boa` to `import boa; import boa_asan` in scripts
from eth.exceptions import VMError
import boa.environment
class MemoryAccessViolation(VMError):
pass
@charles-cooper
charles-cooper / defillama.py
Created April 9, 2023 17:42
defillama chatgpt plugin generated by chatgpt
import requests
from openai_plugin import Plugin
class DefiLlama(Plugin):
def __init__(self):
self.base_url = "https://api.llama.fi"
def fetch_data(self, endpoint):
try:
response = requests.get(f"{self.base_url}/{endpoint}")