All Projects → dydxprotocol → Protocol_v1

dydxprotocol / Protocol_v1

Licence: apache-2.0
[DEPRECATED] Solidity Smart Contracts for the dYdX V1 Margin Trading Protocol

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Labels

Projects that are alternatives of or similar to Protocol v1

Ethers Rs
Complete Ethereum & Celo library and wallet implementation in Rust. https://docs.rs/ethers
Stars: ✭ 145 (-6.45%)
Mutual labels:  ethereum
0x Mesh
A peer-to-peer network for sharing 0x orders
Stars: ✭ 149 (-3.87%)
Mutual labels:  ethereum
React Native Geth
Ethereum Light-Client implementation for React Native
Stars: ✭ 152 (-1.94%)
Mutual labels:  ethereum
Sablier
The protocol for real-time finance on the Ethereum blockchain
Stars: ✭ 147 (-5.16%)
Mutual labels:  ethereum
Ebtc
eBitcoin (eBTC) is an ERC20 token. Its primary utility is to provide an easy & fast payment solution. Its edge over other tokens is that it is capable of sending up to 255 payments in a single transaction.
Stars: ✭ 149 (-3.87%)
Mutual labels:  ethereum
Erc20 Rest Service
ERC-20 token standard RESTful service using Spring Boot and web3j
Stars: ✭ 150 (-3.23%)
Mutual labels:  ethereum
Tokens
Ethereum token definitions
Stars: ✭ 144 (-7.1%)
Mutual labels:  ethereum
Defi Score
DeFi Score: An open framework for evaluating DeFi protocols
Stars: ✭ 152 (-1.94%)
Mutual labels:  ethereum
Awesome Token Sale
Curated list of token sale resources / ICO resources
Stars: ✭ 149 (-3.87%)
Mutual labels:  ethereum
Tokenbase
A repository of ERC20 token information. Tokens listed are tradeable on https://forkdelta.github.io. We welcome contributions! 🎉
Stars: ✭ 152 (-1.94%)
Mutual labels:  ethereum
Raiden
Raiden Network
Stars: ✭ 1,825 (+1077.42%)
Mutual labels:  ethereum
Pm Contracts
Collection of smart contracts for the Gnosis prediction market platform.
Stars: ✭ 148 (-4.52%)
Mutual labels:  ethereum
Set Protocol Contracts
🎛 Set Protocol Smart Contracts
Stars: ✭ 151 (-2.58%)
Mutual labels:  ethereum
Nsfminer
No Fee Ethash miner for AMD and Nvidia
Stars: ✭ 141 (-9.03%)
Mutual labels:  ethereum
Chainlink Ruby
Easily connect your applications to blockchains
Stars: ✭ 152 (-1.94%)
Mutual labels:  ethereum
Bitnation Constitution
Decentralized Borderless Voluntary Nation (DBVN) Liquid Holocracy Constitution
Stars: ✭ 144 (-7.1%)
Mutual labels:  ethereum
Sparkle Airdrop
Sparkle Airdrop Contract Built on Ethereum
Stars: ✭ 150 (-3.23%)
Mutual labels:  ethereum
Ethers.objc
Fast, simple and complete library for Ethereum in Objective-C.
Stars: ✭ 154 (-0.65%)
Mutual labels:  ethereum
Cryptocurrency Icons
A set of icons for all the main cryptocurrencies and altcoins, in a range of styles and sizes.
Stars: ✭ 2,116 (+1265.16%)
Mutual labels:  ethereum
Rattle
evm binary static analysis
Stars: ✭ 152 (-1.94%)
Mutual labels:  ethereum

CI Coverage Status License NPM Docker Slack

DEPRECATED see our new protocol here

Source code for Ethereum Smart Contracts used by the dYdX Margin Trading Protocol

Whitepaper

Short & Leveraged Long Tokens Whitepaper

Npm Package

The npm package contains the deployed addresses of the contracts, and also allows access to seed positions and orders on the docker test container

Install

npm install --save @dydxprotocol/protocol

Contracts

import { Margin as MarginContract } from '@dydxprotocol/protocol';
import truffleContract from 'truffle-contract';

async function openPosition(provider, networkId) {
  const Margin = truffleContract(MarginContract);

  Margin.setProvider(provider);
  Margin.setNetwork(networkId);

  const margin = await Margin.deployed();

  await margin.openPosition(...);
}

Seed Positions / Orders

Seed positions are available and already deployed on the docker container

import { seeds } from '@dydxprotocol/protocol';

const position = seeds.positions[2];

console.log(position.id);
console.log(position.isTokenized);

// Test 0x V1 orders. Maker already has balance and allowance set
const order = seeds.orders[1];

console.log(order.maker);

Snapshotting

When using the docker container, you can reset the evm to the default state. This can be useful when running automated test suites

import { resetEVM } from '@dydxprotocol/protocol';

await resetEVM(web3.currentProvider);

Docker Container

Docker container with a a deployed version of the protocol running on a ganache-cli node with network_id = 1212. Docker container versions correspond to npm versions of this package, so use the same version for both

docker pull dydxprotocol/protocol
docker run dydxprotocol/protocol

Docker Compose

# docker-compose.yml

version: '3'
services:
  protocol:
    image: dydxprotocol/protocol:latest
    ports:
      - 8545:8545

Development

Install

npm install

Compile

npm run compile

Test

npm test

Lint

Lint the javascript files (tests, deploy scripts)

npm run lint

Lint the solidity files (all smart contracts)

npm run solint

Lint the solidity files (custom dYdX linter)

npm run dydxlint

Architecture

Contracts

Base Protocol

Margin.sol

Contains business logic for margin trading. All external functions for margin trading are in this contract.

TokenProxy.sol

Used to transfer user funds. Users set token allowance for the proxy authorizing it to transfer their funds. Only allows authorized contracts to transfer funds.

Vault.sol

Holds all token funds. Is authorized to transfer user funds via the TokenProxy. Allows authorized contracts to withdraw funds.

Second Layer

ZeroExV1ExchangeWrapper.sol

Allows positions to be opened or closed using 0x orders. Wraps the 0x Exchange Contract in a standard interface usable by Margin.

ERC20Short.sol

Allows short positions to be tokenized as ERC20 tokens. Ownership of a short token grants ownership of a proportional piece of the backing position.

ERC20Long.sol

Allows leveraged long positions to be tokenized as ERC20 tokens. Ownership of a leveraged long token grants ownership of a proportional piece of the backing position.

ERC721Position.sol

Allows margin positions to be represented as ERC721 tokens.

ERC721MarginLoan.sol

Allows loans to be represented as ERC721 tokens.

DutchAuctionCloser.sol

Allows margin positions to be automatically close via a dutch auction.

SharedLoan.sol

Allows multiple lenders to share in a loan position together.

Read more about our smart contract architecture here

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].