Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
add exit dai function and test
Browse files Browse the repository at this point in the history
  • Loading branch information
b-pmcg committed Apr 16, 2021
1 parent 51b0a24 commit 88adaee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/dai-plugin-liquidations/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@makerdao/dai-plugin-liquidations",
"description": "Plugin to add liquidations to dai.js",
"version": "0.1.0-beta10",
"version": "0.1.0-beta11",
"license": "MIT",
"main": "dist/index.js",
"unpkg": "umd/index.js",
Expand Down
14 changes: 11 additions & 3 deletions packages/dai-plugin-liquidations/src/LiquidationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ export default class LiquidationService extends PublicService {
}

async getHoleAndDirtForIlk(ilk) {
const data = await this._dogContract()
.ilks(stringToBytes(ilk));
const data = await this._dogContract().ilks(stringToBytes(ilk));
const hole = new BigNumber(data.hole).div(RAD);
const dirt = new BigNumber(data.dirt).div(RAD);
const diff = hole.minus(dirt);
Expand Down Expand Up @@ -282,12 +281,21 @@ export default class LiquidationService extends PublicService {
}

@tracksTransactions
async joinDaiToAdapter(address, amount, { promise }) {
async joinDaiToAdapter(amount, { promise }) {
const address = this.get('web3').currentAddress();
const amt = BigNumber(amount)
.times(WAD)
.toFixed();
return await this._joinDaiAdapter().join(address, amt, { promise });
}
@tracksTransactions
async exitDaiFromAdapter(amount, { promise }) {
const address = this.get('web3').currentAddress();
const amt = BigNumber(amount)
.times(WAD)
.toFixed();
return await this._joinDaiAdapter().exit(address, amt, { promise });
}

@tracksTransactions
async bark(ilk, urn, { promise }) {
Expand Down
27 changes: 25 additions & 2 deletions packages/dai-plugin-liquidations/test/LiquidationService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function makerInstance(preset) {
}

beforeAll(async () => {
// To run this test on kovan, just switch the network variables below
// To run this test on kovan, just switch the network variables below:
// network = 'kovan';
network = 'test';
maker = await makerInstance(network);
Expand Down Expand Up @@ -79,7 +79,7 @@ test('can join DAI to the vat', async () => {
.dai(maker.currentAddress());

const joinAmt = 80;
await service.joinDaiToAdapter(maker.currentAddress(), joinAmt);
await service.joinDaiToAdapter(joinAmt);

const vatDaiBalAfter = await maker
.service('smartContract')
Expand All @@ -95,6 +95,29 @@ test('can join DAI to the vat', async () => {
);
});

test('can exit DAI from the vat', async () => {
const vatDaiBalBefore = await maker
.service('smartContract')
.getContract('MCD_VAT')
.dai(maker.currentAddress());

const exitAmt = 5;
await service.exitDaiFromAdapter(exitAmt);

const vatDaiBalAfter = await maker
.service('smartContract')
.getContract('MCD_VAT')
.dai(maker.currentAddress());

expect(vatDaiBalAfter).toEqual(
vatDaiBalBefore.sub(
BigNumber(exitAmt)
.times(RAD)
.toFixed()
)
);
});

xtest('can successfully bid on an auction', async () => {
// // const id =
// // '0x000000000000000000000000000000000000000000000000000000000000000f';
Expand Down

0 comments on commit 88adaee

Please sign in to comment.