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

Commit

Permalink
add getSystemSurplus function
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler17 committed May 22, 2020
1 parent 378bac3 commit 0436bbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/dai-plugin-mcd/src/SystemDataService.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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));

This comment has been minimized.

Copy link
@jparklev

jparklev Jun 5, 2020

Contributor

Running the gov portal on kovan, i was getting an error like currency can't be negative here. Looking at this line, i'm wondering if sin is higher than dai on kovan? Is there a safe way to make the currency object negative if so? cc @tyler17 @levity

This comment has been minimized.

Copy link
@tyler17

tyler17 Jun 5, 2020

Author Collaborator

Yeah that must be it. What's the rationale for not allowing negative numbers in the currency object?

This comment has been minimized.

Copy link
@levity

levity Jun 6, 2020

Contributor

at the time, we didn't need to represent negative numbers, so my hope was that being more strict would help catch bugs. guess it's time to relax that restriction as well

This comment has been minimized.

Copy link
@levity

levity Jun 6, 2020

Contributor

just published 0.9.9 which removes the restriction

}

// Helpers ----------------------------------------------

get cat() {
Expand Down
7 changes: 7 additions & 0 deletions packages/dai-plugin-mcd/test/SystemDataService.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mcdMaker } from './helpers';
import { ServiceRoles } from '../src/constants';
import { MDAI } from '../src/index';

let service;
let maker;
Expand All @@ -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
});

0 comments on commit 0436bbe

Please sign in to comment.