From 0436bbe28f4f5beee435a7d1dda1f1689867c3ac Mon Sep 17 00:00:00 2001 From: Tyler Sorensen Date: Thu, 21 May 2020 17:29:22 -0700 Subject: [PATCH] add getSystemSurplus function --- packages/dai-plugin-mcd/src/SystemDataService.js | 10 ++++++++++ packages/dai-plugin-mcd/test/SystemDataService.spec.js | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/packages/dai-plugin-mcd/src/SystemDataService.js b/packages/dai-plugin-mcd/src/SystemDataService.js index 1cc1f76a6..4ce4cb418 100644 --- a/packages/dai-plugin-mcd/src/SystemDataService.js +++ b/packages/dai-plugin-mcd/src/SystemDataService.js @@ -1,6 +1,7 @@ import { PublicService } from '@makerdao/services-core'; import { RAD, RAY, ServiceRoles, SECONDS_PER_YEAR } from './constants'; import BigNumber from 'bignumber.js'; +import { MDAI } from './index'; export default class SystemDataService extends PublicService { constructor(name = ServiceRoles.SYSTEM_DATA) { @@ -33,6 +34,15 @@ export default class SystemDataService extends PublicService { return live.eq(0); } + async getSystemSurplus() { + const vowAddr = this.get('smartContract').getContractAddress('MCD_VOW'); + const [ dai, sin ] = await Promise.all([ + this.vat.dai(vowAddr), + this.vat.sin(vowAddr) + ]); + return MDAI.rad(dai).minus(MDAI.rad(sin)); + } + // Helpers ---------------------------------------------- get cat() { diff --git a/packages/dai-plugin-mcd/test/SystemDataService.spec.js b/packages/dai-plugin-mcd/test/SystemDataService.spec.js index 4d9ac5921..c47d4b618 100644 --- a/packages/dai-plugin-mcd/test/SystemDataService.spec.js +++ b/packages/dai-plugin-mcd/test/SystemDataService.spec.js @@ -1,5 +1,6 @@ import { mcdMaker } from './helpers'; import { ServiceRoles } from '../src/constants'; +import { MDAI } from '../src/index'; let service; let maker; @@ -23,3 +24,9 @@ test('get global settlement status', async () => { const cage = await service.isGlobalSettlementInvoked(); expect(cage).toBe(false); }); + +test('get system surplus', async () => { + const surplus = await service.getSystemSurplus(); + console.log('surplus.toNumber', surplus.toNumber()); + expect(surplus).toEqual(MDAI(0)); //TODO change to expect non-zero number +});