Coder Social home page Coder Social logo

mcd4j's Introduction

mcd4j

Java library for interacting with MCD

Prerequisite:

  • java
  • maven

Build:

mvn clean
mvn package -Dmaven.test.skip=true
Install in local maven repository:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=target/mcd4j-1.0-SNAPSHOT.jar
Use in pom.xml:
    <dependency>
        <groupId>org.makerdao</groupId>
        <artifactId>mcd4j</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

Usage:

String registeredEthAccount = "0xD71..........";

// Instantiate Mcd object
Mcd mcd = new Mcd(web3j, credentials, gasProvider);

// get services
SavingsService savingsService = mcd.getSavingsService();
DSProxyService dsProxyService = mcd.getDSProxyService();
AllowanceService allowanceService = mcd.getAllowanceService();

// 1 - get ds proxy for registered ETH account, if no proxy then create one.
// Subsequent calls to DSProxyService.getProxy return same instance of DSProxy object
DSProxy dsProxy = dsProxyService.getProxy(registeredEthAccount, true);

// 2 - set proxy allowance of 10 DAI
allowanceService.requireAllowance(registeredEthAccount,
                    dsProxy.getContractAddress(),
                    TokenSymbol.DAI,
                    BigDecimal.TEN);

// 3 - join 3 DAI
TransactionReceipt receiptJoinThreeDai = savingsService.join(dsProxy, BigDecimal.valueOf(3));
// Do something with TransactionReceipt
// check proxy DSR balance
BigDecimal myDsrBalance = savingsService.getBalanceOf(dsProxy.getContractAddress());

// 4 - exit 1 DAI
TransactionReceipt receiptExitOneDai = savingsService.exit(dsProxy, BigDecimal.ONE);
// Do something with TransactionReceipt

// 5 - exit all DAI
TransactionReceipt receiptExitAllDai = savingsService.exitAll(dsProxy);
// Do something with TransactionReceipt

// 6 - remove proxy actions allowance
allowanceService.removeAllowance(registeredEthAccount,
                     dsProxy.getContractAddress(),
                     TokenSymbol.DAI);

See examples/DsrExample.java for an example

Testing

Prerequisites:

  • dai.js testchain started (see https://github.com/makerdao/dai.js#running-the-testchain)
  • testchain account 0x16fb96a5fa0427af0c8f7cf1eb4870231c8154b6 funded with 60 DAI or more (in dai.js run node_modules/.bin/babel-node packages/test-helpers/scripts/generateDai.js 0x16fb96a5fa0427af0c8f7cf1eb4870231c8154b6 60)

For running tests on testchain: mvn test

mcd4j's People

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.