npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@makerdao/dai-plugin-eth2dai-direct

v0.1.0

Published

A dai.js plugin for atomic trading on maker otc

Downloads

2

Readme

This plugin can be injected into dai.js to execute atomic trades on Eth2Dai. It uses the contract FKA Oasis Direct Proxy to interact with the underlying Maker OTC contract.

NPM Build Status GitHub License


Usage

To configure the SDK with this plugin:

$ yarn add @makerdao/dai
$ yarn add @makerdao/dai-plugin-eth2dai-direct
import Maker from '@makerdao/dai';
import Eth2DaiDirect from '@makerdao/dai-plugin-eth2dai-direct';

const maker = await Maker.create('browser', {
  plugins: [Eth2DaiDirect]
});
await maker.authenticate();
await maker.service('exchange').sell('ETH', 'DAI', '0.5');

Note that the 'browser' preset above is only an example, not a specific requirement of the Eth2Dai Direct plugin. For more information about available presets, configuration options, and additional plugins, check the dai.js docs.


The Eth2DaiDirectService normalizes the syntax across different types of trades, so the main functionality is represented simply by sell and buy. The difference between these two functions is the value defined explicitly as a parameter; for example, a user might want to sell one hundred Dai for however much ETH that Dai can buy.

The valid token symbols for either side of any trade are 'ETH', 'WETH', 'PETH', and 'DAI'.


  • sell takes three parameters: the sellToken (string), the buyToken (string), and the amount (string or number)
maker.service('exchange').sell('ETH', 'DAI', '1');
  • buy takes three parameters: the buyToken (string), the sellToken (string), and the amount (string or number)
maker.service('exchange').buy('DAI', 'ETH', 150);

The service can also query the OTC contract for the buy amount for a supplied pay amount and the pay amount for a supplied buy amount. If the price of the exchange deviates from this estimate by more than a configurable slippage limit, the trade will be reverted.


  • getBuyAmount takes three parameters: buyToken (string), sellToken (string), and sellAmount (string or number)
const amount = await maker.service('exchange').getBuyAmount('DAI', 'ETH', 150);
  • getPayAmount takes three paramaters: sellToken (string), buyToken (string), and buyAmount (string or number)
const amount = await maker.service('exchange').getPayAmount('ETH', 'DAI', '1');
  • setSlippageLimit takes one parameter: limit (float). The default slippage limit is 0.02, or 2%.
maker.service('exchange').setSlippageLimit(0.05);

Development

$ git clone https://github.com/makerdao/dai-plugin-eth2dai-direct.git
$ cd dai-plugin-eth2dai-direct/
$ yarn
$ git submodule update --init --recursive
  • Run tests with yarn test
  • Run testnet with yarn test:net. This will run by default with yarn test, but can also run independently
  • Build for publication with yarn build