Skip to content

Instantly share code, notes, and snippets.

View liamzebedee's full-sized avatar
™️
'drop all repos

Liam Zebedee liamzebedee

™️
'drop all repos
View GitHub Profile
@liamzebedee
liamzebedee / hacks.rs
Created May 22, 2022 03:43
Rust hacks
// f256.
// use std::ops::{Deref, DerefMut};
// #[derive(Clone, Copy, Debug)]
// pub struct Felt(BaseElement);
// impl Deref for Felt {
// type Target = Felt;
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import get_caller_address
from strings import Str
# ------------------
# Storage.
async function getProfiles(ids: string[]) {
const res2 = await fetch(`${ANNONCE_SUBGRAPH_URL}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
mode: 'cors',
body: JSON.stringify({
query: `
@liamzebedee
liamzebedee / wallet.js
Last active March 3, 2022 02:54
Create a HD wallet using ethers.js v5
// Follow me you degenerate
// https://twitter.com/liamzebedee
const ethers = require('ethers')
const HD_PATH_BASE = "m/44'/60'/0'/0"
const wallet = ethers.Wallet.createRandom()
console.log(`path: ${HD_PATH_BASE}`)
console.log(`mnemonic: ${wallet.mnemonic.phrase}`)

A small walkthrough on futures logic:

A position consists of (size, leverage, margin). A margin is essentially the collateralisation for a futures position. In a simple example, you can think of opening a MakerDAO Vault as a position with 1x leverage and a margin equal to min-c-ratio * dai_generated. The dai_generated would represent the size of your position, and the 150% * eth_price * locked_amount is your min initial margin.

The leverage is used to determine your position size. So I could open a 1x ETH LONG position on MakerDAO as we described before, and liquidation risk would essentially follow linearly wiht price movement. If I doubled my leverage, it would mean that I am 2x as exposed to the price movements.

When implementing futures contracts, the leverage can change but the margin remains constant. So for example, trader A has a position of 10 ETH and 1x leverage, and trader B has a position of 10 ETH and 5x leverage. Using the dYdX ETH perpetuals contracts as an example, the initial mar

contract OVMTimestampOracle {
constructor(uint initial_rate) public {
rate = initial_rate;
}
// Last block.number.
uint public last_n;
// Last block.timestamp.
uint public last_t;
describe.skip('publish scripts (l2)', async () => {
const { buildPath, network, useOvm } = {
network: 'local',
useOvm: true,
buildPath: path.join(__dirname, '..', '..', `${BUILD_FOLDER}-ovm`),
};
const { getSource, getTarget, /* getSynths, */ getPathToNetwork, getFuturesMarkets } = wrap({
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.7/interfaces/LinkTokenInterface.sol";
import "@chainlink/contracts/src/v0.7/vendor/SafeMathChainlink.sol";
import "./vendor/Owned.sol";
import "./vendor/Address.sol";
import "./vendor/ReentrancyGuard.sol";
@liamzebedee
liamzebedee / pool.sol
Created March 4, 2021 05:34
Creating a Balancer pool in Solidity
function createPool(
uint256[3] calldata amounts
)
external
isOpen
returns (address)
{
address creator = msg.sender;
require(address(pool) == address(0), "createPool can only be called once");
@liamzebedee
liamzebedee / README.md
Created February 16, 2021 12:12 — forked from miguelmota/README.md
Deploy custom Optimism rollup instructions

Instructions

Unofficial guide on deploying a custom Optimism rollup on Kovan

Clone optimism contracts:

git clone https://github.com/ethereum-optimism/contracts-v2.git