Code Monkey home page Code Monkey logo

dydx.js's Introduction

CI Coverage Status License NPM Slack

DEPRECATED see our new protocol here

A TypeScript library for interacting with the dYdX protocol.

Usage

Install

npm install --save @dydxprotocol/dydx.js

Initialize

import { DYDX } from '@dydxprotocol/dydx.js';

const dydx = new DYDX();
await dydx.initialize(provider, networkId);

Short & Leveraged Tokens

Mint

await dydx.shortToken.mint(
  positionId,
  trader,
  tokensToMint,
  payInHeldToken,
  exchangeWrapper,
  orderData,
  options,
);

Or mint with ETH:

await dydx.shortToken.mintWithETH(
  positionId,
  trader,
  tokensToMint,
  ethToSend,
  ethIsHeldToken,
  exchangeWrapper,
  orderData,
  options,
);

Or mint directly (you will put up all held token [DAI for sETH] and will receive owed token [WETH for sETH]):

// Set your allowance on our proxy contract - you only need to do this once
await dydx.token.setMaximumProxyAllowance(
  heldTokenAddress, // DAI address for sETH
  traderAddress, // your address
);

await dydx.shortToken.mintDirectly(
  positionId, // Can get from expo API
  trader, // your address
  tokensToMint, // BigNumber - Number of tokens to mint in base units (10^18 is 1 sETH)
);

Close

Close directly (you will pay all owed token owed to lenders [WETH for sETH] and will receive all held token collateral [DAI for sETH])

// Set your allowance on our proxy contract - you only need to do this once
await dydx.token.setMaximumProxyAllowance(
  owedTokenAddress, // WETH address for sETH
  traderAddress, // your address
);

await dydx.shortToken.closeDirectly(
  positionId, // Can get from expo API
  closer, // your address
  tokensToClose, // BigNumber - Number of tokens to close in base units (10^18 is 1 sETH)
);

Development

Install

npm install

Compile

npm run build

dydx.js's People

Contributors

antoniojuliano avatar brendanchou avatar prettymuchbryce avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.