Skip to content

Instantly share code, notes, and snippets.

@aleph-v
aleph-v / CurveInterface.sol
Created July 6, 2021 15:08
Vyper interface
pragma solidity ^0.8.0;
interface CurveContract {
function calc_withdraw_one_coin(uint256 token_amount, uint256 i) external view returns(uint256);
}
pragma solidity ^0.8.0;
interface CoreVoting {
enum Ballot {
YES,
NO,
MAYBE
}
@aleph-v
aleph-v / buy.ts
Created May 24, 2021 15:54
Example trade which buys pt
import { Vault__factory } from "typechain/factories/Vault__factory";
import { ethers } from "hardhat";
import * as readline from "readline-sync";
const BALANCER_VAULT_ADDRESS = "";
const PT_POOL_ADDRESS = "";
const PT_ADDRESS = "";
const UNDERLYING_ADDRESS = "";
const UNDERLYING_DECIMALS = 18;
@aleph-v
aleph-v / permitFunction.ts
Last active April 29, 2021 17:21
An async permit signing function
// Uses a default infinite expiration time
async function getPermitSignature(
token: ERC20Permit,
sourceAddr: string,
spenderAddr: string,
spenderAmount: BigNumberish,
version: string
) {
// To be replaced in front end with signer type from ethers
function americanPut(T, S, K, r, sigma, q, n)
{
' T... expiration time
' S... stock price
' K... strike price
' q... dividend yield
' n... height of the binomial tree
deltaT := T / n;
up := exp(sigma * sqrt(deltaT));
p0 := (up*exp(-q * deltaT) - exp(-r * deltaT)) / (up^2 - 1);
use zkp_stark::{*, primefield::*};
#[derive(Clone, Debug)]
struct Claim {
index: usize,
value: FieldElement,
}
#[derive(Clone, Debug)]
struct Witness {
Compiling substrate-node v1.0.0 (/Users/pvienhage/dev/starkcrypto/substrate-node)
Compiling substrate-runtime v1.0.0 (/Users/pvienhage/dev/starkcrypto/substrate-runtime)
error[E0412]: cannot find type `Event` in this scope
--> substrate-runtime/src/exchange.rs:50:1
|
50 | / decl_module! {
51 | | /// The module declaration.
52 | | pub struct Module<T: Trait> for enum Call where origin: T::Origin {
53 | | // Initializing events
... |
pragma solidity ^0.4.24;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../introspection/ERC165.sol";
/**
* @title ERC721 Non-Fungible Token Standard basic implementation
@aleph-v
aleph-v / ERC720_delegated.sol
Last active January 12, 2019 02:16
Delegated ERC721 with nonce
pragma solidity ^0.4.24;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../introspection/ERC165.sol";
/**
* @title ERC721 Non-Fungible Token Standard basic implementation with added support for metatransactions
@aleph-v
aleph-v / superAssembly.sol
Last active January 6, 2022 02:59
Super assembly optomized version of spec256r verification, takes sig verification from ~900K to ~300K gas
// Partially derived from code by Lionello Lunesu
pragma solidity ^0.5.2;
contract ModExp {
// address constant MODEXP_BUILTIN = 0x0000000000000000000000000000000000000005;
function modexp(uint256 b, uint256 e, uint256 m) internal returns(uint256 result) {