From 88adaee99694ee3baa10a97446c07e770f764bd7 Mon Sep 17 00:00:00 2001 From: Phil Bain Date: Fri, 16 Apr 2021 15:42:56 -0600 Subject: [PATCH] add exit dai function and test --- packages/dai-plugin-liquidations/package.json | 2 +- .../src/LiquidationService.js | 14 +++++++--- .../test/LiquidationService.test.js | 27 +++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/dai-plugin-liquidations/package.json b/packages/dai-plugin-liquidations/package.json index 860a0ede7..d381d554f 100644 --- a/packages/dai-plugin-liquidations/package.json +++ b/packages/dai-plugin-liquidations/package.json @@ -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", diff --git a/packages/dai-plugin-liquidations/src/LiquidationService.js b/packages/dai-plugin-liquidations/src/LiquidationService.js index 289202ec6..f05f2d569 100644 --- a/packages/dai-plugin-liquidations/src/LiquidationService.js +++ b/packages/dai-plugin-liquidations/src/LiquidationService.js @@ -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); @@ -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 }) { diff --git a/packages/dai-plugin-liquidations/test/LiquidationService.test.js b/packages/dai-plugin-liquidations/test/LiquidationService.test.js index 965889c87..229c5b76c 100644 --- a/packages/dai-plugin-liquidations/test/LiquidationService.test.js +++ b/packages/dai-plugin-liquidations/test/LiquidationService.test.js @@ -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); @@ -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') @@ -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';