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

Sdk 779 remove vdb #215

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 1 addition & 55 deletions packages/dai-plugin-mcd/src/CdpManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { castAsCurrency, stringToBytes, bytesToString } from './utils';
import has from 'lodash/has';
import padStart from 'lodash/padStart';
import { MDAI, ETH, GNT } from './index';
const { CDP_MANAGER, CDP_TYPE, SYSTEM_DATA, QUERY_API } = ServiceRoles;
import BigNumber from 'bignumber.js';
import { RAY } from './constants';
const { CDP_MANAGER, CDP_TYPE, SYSTEM_DATA } = ServiceRoles;
import getEventHistoryImpl from './EventHistory';

export default class CdpManager extends LocalService {
Expand All @@ -21,7 +19,6 @@ export default class CdpManager extends LocalService {
'smartContract',
CDP_TYPE,
SYSTEM_DATA,
QUERY_API,
'accounts',
'proxy',
'token',
Expand Down Expand Up @@ -73,21 +70,6 @@ export default class CdpManager extends LocalService {
return debts.reduce((a, b) => a.plus(b));
}

async getCombinedEventHistory(proxyAddress) {
const cdpIds = await this.getCdpIds(proxyAddress);
const ilksAndUrns = await Promise.all(
cdpIds.map(async c => {
const urn = await this.getUrn(c.id);
const ilk = stringToBytes(c.ilk);
return { urn, ilk };
})
);
const events = await this.get(QUERY_API).getCdpEventsForArrayOfIlksAndUrns(
ilksAndUrns
);
return this.parseFrobEvents(events, this.get(CDP_TYPE));
}

@tracksTransactions
async open(ilk, { promise, cache = true }) {
const proxy = await this.get('proxy').ensureProxy({ promise });
Expand Down Expand Up @@ -326,42 +308,6 @@ export default class CdpManager extends LocalService {
return this._manager.owns(this.getIdBytes(id));
}

parseFrobEvents(events) {
return events.map(e => {
const ilk = e.ilkIdentifier;
const currency = this.get(CDP_TYPE).getCdpType(null, ilk).currency;
const transactionHash = e.tx.transactionHash;
const rate = new BigNumber(e.ilkRate.toString()).dividedBy(RAY);
const changeInCollateral = currency.wei(Math.abs(e.dink));
let collateralAction;
if (parseInt(e.dink) !== 0) {
collateralAction = parseInt(e.dink) > 0 ? 'lock' : 'free';
}
const dart = MDAI.wei(Math.abs(e.dart));
const changeInDai = dart.times(rate);
let daiAction;
if (parseInt(e.dart) !== 0) {
daiAction = parseInt(e.dart) > 0 ? 'draw' : 'wipe';
}
const time = new Date(e.tx.era.iso);
const senderAddress = e.tx.txFrom;
//const resultingCollateral = currency.wei(e.urn.nodes[0].ink);
//const resultingDebt = MDAI.wei(e.urn.nodes[0].art);
return {
transactionHash,
changeInCollateral,
collateralAction,
changeInDai,
daiAction,
ilk,
time,
senderAddress
//resultingCollateral,
//resultingDebt
};
});
}

getIdBytes(id, prefix = true) {
assert(typeof id === 'number', 'ID must be a number');
return (prefix ? '0x' : '') + padStart(id.toString(16), 24, '0');
Expand Down
16 changes: 0 additions & 16 deletions packages/dai-plugin-mcd/src/CdpType.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ export default class CdpType {
return math.annualStabilityFee(this._getCached('jugInfo').duty);
}

async getPriceHistory(num = 100) {
const prices = await this._cdpTypeService
.get(ServiceRoles.QUERY_API)
.getPriceHistoryForPip(this._pipAddress, num);
return Promise.all(
prices.map(async e => {
const price = this.currency.wei(e.val);
//todo: update this query to read the datetime directly from vdb once vdb is updated with that functionality
const timestamp = (await this._web3Service.getBlock(e.blockNumber))
.timestamp;
const time = new Date(1000 * timestamp);
return { price, time };
})
);
}

async ilkInfo(contract = 'vat') {
return this._systemData[contract].ilks(this._ilkBytes);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dai-plugin-mcd/src/CdpTypeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { PublicService } from '@makerdao/services-core';
import CdpType from './CdpType';
import { ServiceRoles } from './constants';
import assert from 'assert';
const { CDP_TYPE, SYSTEM_DATA, QUERY_API } = ServiceRoles;
const { CDP_TYPE, SYSTEM_DATA } = ServiceRoles;
import * as math from './math';

export default class CdpTypeService extends PublicService {
constructor(name = CDP_TYPE) {
super(name, [SYSTEM_DATA, QUERY_API]);
super(name, [SYSTEM_DATA]);
}

initialize(settings = {}) {
Expand Down
12 changes: 0 additions & 12 deletions packages/dai-plugin-mcd/src/ManagedCdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ export default class ManagedCdp {
return this._cdpManager.getOwner(this.id);
}

async getEventHistory() {
const urn = await this.getUrn();
const events = await this._cdpManager
.get(ServiceRoles.QUERY_API)
.getCdpEventsForIlkAndUrn(this.ilk, urn);
return this._cdpManager.parseFrobEvents(
events,
this._cdpManager.get(ServiceRoles.CDP_TYPE)
);
}

//todo: add caching?
getUrn() {
return this._cdpManager.getUrn(this.id);
}
Expand Down
89 changes: 0 additions & 89 deletions packages/dai-plugin-mcd/src/QueryApiMcdService.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/dai-plugin-mcd/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const ServiceRoles = {
CDP_TYPE: 'mcd:cdpType',
AUCTION: 'mcd:auction',
SYSTEM_DATA: 'mcd:systemData',
QUERY_API: 'mcd:queryApi',
SAVINGS: 'mcd:savings'
};

Expand Down
14 changes: 2 additions & 12 deletions packages/dai-plugin-mcd/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ import SavingsService from './SavingsService';
import CdpTypeService from './CdpTypeService';
import AuctionService from './AuctionService';
import SystemDataService from './SystemDataService';
import QueryApiMcdService from './QueryApiMcdService';
import { ServiceRoles as ServiceRoles_ } from './constants';
import BigNumber from 'bignumber.js';

export const ServiceRoles = ServiceRoles_;
const {
CDP_MANAGER,
CDP_TYPE,
SYSTEM_DATA,
AUCTION,
QUERY_API,
SAVINGS
} = ServiceRoles;
const { CDP_MANAGER, CDP_TYPE, SYSTEM_DATA, AUCTION, SAVINGS } = ServiceRoles;

// look up contract ABIs using abiMap.
// if an exact match is not found, prefix-match against keys ending in *, e.g.
Expand Down Expand Up @@ -141,15 +133,13 @@ export const McdPlugin = {
CDP_TYPE,
AUCTION,
SYSTEM_DATA,
QUERY_API,
SAVINGS
],
[CDP_TYPE]: [CdpTypeService, { cdpTypes, prefetch }],
[CDP_MANAGER]: CdpManager,
[SAVINGS]: SavingsService,
[AUCTION]: AuctionService,
[SYSTEM_DATA]: SystemDataService,
[QUERY_API]: QueryApiMcdService
[SYSTEM_DATA]: SystemDataService
};
}
};
Expand Down
16 changes: 0 additions & 16 deletions packages/dai-plugin-mcd/test/CdpManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { mcdMaker, setupCollateral } from './helpers';
import { setMethod, transferToBag } from '../src/CdpManager';
import { ServiceRoles } from '../src/constants';
import { ETH, MDAI, GNT, DGD, BAT } from '../src';
import { dummyEventData, formattedDummyEventData } from './fixtures';
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';

import TestAccountProvider from '@makerdao/test-helpers/src/TestAccountProvider';

let maker, cdpMgr, txMgr, snapshotData;
Expand Down Expand Up @@ -82,20 +80,6 @@ test('getCdp can disable prefetch', async () => {
expect(sameCdp._urnInfoPromise).toBeUndefined();
});

test('getCombinedEventHistory', async () => {
const proxy = await maker.currentProxy();
const mockFn = jest.fn(async () => dummyEventData('ETH-A'));
maker.service(
ServiceRoles.QUERY_API
).getCdpEventsForArrayOfIlksAndUrns = mockFn;
const events = await cdpMgr.getCombinedEventHistory(proxy);
expect(mockFn).toBeCalled();
const GEM = maker
.service(ServiceRoles.CDP_TYPE)
.getCdpType(null, events[0].ilk).currency;
expect(events).toEqual(formattedDummyEventData(GEM, events[0].ilk));
});

test('transaction tracking for openLockAndDraw', async () => {
const cdpMgr = maker.service(ServiceRoles.CDP_MANAGER);
const txMgr = maker.service('transactionManager');
Expand Down
24 changes: 1 addition & 23 deletions packages/dai-plugin-mcd/test/CdpType.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createCurrencyRatio } from '@makerdao/currency';
import { mcdMaker, setupCollateral } from './helpers';
import { ServiceRoles } from '../src/constants';
import { ETH, MDAI, USD, BAT } from '../src';
const { CDP_MANAGER, CDP_TYPE, QUERY_API } = ServiceRoles;
const { CDP_MANAGER, CDP_TYPE } = ServiceRoles;

let maker, service;

Expand Down Expand Up @@ -78,28 +78,6 @@ describe.each(scenarios)('%s', (ilk, GEM) => {
);
});

test('get price history', async () => {
const dummyData = [
{
val: '177315000000000000000',
blockNumber: '1'
}
];
const formattedDummyData = [
{
price: GEM(177.315),
time: new Date(
1000 * (await cdpType._web3Service.getBlock(1)).timestamp
)
}
];
const mockFn = jest.fn(async () => dummyData);
maker.service(QUERY_API).getPriceHistoryForPip = mockFn;
const prices = await cdpType.getPriceHistory();
expect(mockFn).toBeCalled();
expect(prices).toEqual(formattedDummyData);
});

test('get ilk id', () => {
expect(cdpType.ilk).toBe(ilk);
});
Expand Down
13 changes: 1 addition & 12 deletions packages/dai-plugin-mcd/test/ManagedCdp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';
import { mcdMaker, setupCollateral } from './helpers';
import { ETH, MDAI, USD, BAT, GNT, DGD } from '../src';
import { ServiceRoles } from '../src/constants';
import { dummyEventData, formattedDummyEventData } from './fixtures';
import { createCurrencyRatio } from '@makerdao/currency';

const { CDP_MANAGER, QUERY_API } = ServiceRoles;
const { CDP_MANAGER } = ServiceRoles;

let dai, maker, proxy, snapshotData, txMgr;

Expand Down Expand Up @@ -159,15 +157,6 @@ describe.each([
await expectValues(cdp, { collateral: 0, debt: 0 });
});

test('getEventHistory', async () => {
const mockFn = jest.fn(async () => dummyEventData(ilk));
maker.service(QUERY_API).getCdpEventsForIlkAndUrn = mockFn;
const cdp = await maker.service(CDP_MANAGER).open(ilk);
const events = await cdp.getEventHistory();
expect(mockFn).toBeCalled();
expect(events).toEqual(formattedDummyEventData(GEM, ilk));
});

test('getOwner', async () => {
const cdp = await maker.service(CDP_MANAGER).open(ilk);
const proxy = await maker.service('proxy').currentProxy();
Expand Down
Loading