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

Commit

Permalink
PsmType service rough scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
Padraic-O-Mhuiris committed Jul 8, 2020
1 parent ecc1b88 commit 19c0247
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 34 deletions.
7 changes: 4 additions & 3 deletions packages/dai-plugin-mcd/contracts/addresses/kovan.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"MCD_JOIN_KNC_A": "0xE42427325A0e4c8e194692FfbcACD92C2C381598",
"MCD_FLIP_KNC_A": "0xf14Ec3538C86A31bBf576979783a8F6dbF16d571",

"MCD_JOIN_PSM_USDC_A": "0xc2FB16712AD538EbcBabB00DfAC5fa511A4cc657",
"MCD_FLIP_PSM_USDC_A": "0x481d4eb969a821B6A8137D9c352aA7a7cBc4C8F2",
"PSM_USDC_A": "0xE13eF5966031A50A8df9D7612366a56e3BB36CB1"
"MCD_FLIP_PSM_USDC_A": "0x481d4eb969a821B6A8137D9c352aA7a7cBc4C8F2"
"MCD_JOIN_PSM_USDC_A": "0xaf774866c4b165b88c558C7891290698cf7Ed6B5",
"PSM_USDC_A": "0xAfB79e262B7A07666161B95992934eB0AE230Fb4",

}
26 changes: 0 additions & 26 deletions packages/dai-plugin-mcd/src/PsmService.js

This file was deleted.

37 changes: 37 additions & 0 deletions packages/dai-plugin-mcd/src/PsmType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import assert from 'assert';
import { stringToBytes } from './utils';
import tracksTransactions from './utils/tracksTransactions';

export default class PsmType {
constructor(
psmTypeService,
{ currency, ilk, decimals },
options = { prefect: true }
) {
assert(currency && ilk, 'currency and ilk are required');

this._psmTypeService = psmTypeService;
this.currency = currency;
this.decimals = decimals;
this.ilk = ilk;
this._ilkBytes = stringToBytes(this.ilk);
this.cache = {};
if (options.prefetch) this.prefetch();
}

get feeIn() {}

get feeOut() {}

prefetch() {}

async reset() {
this._prefetchPromise = null;
this.cache = {};
}

_getCached(name) {
assert(this.cache[name], `${name} is not cached`);
return this.cache[name];
}
}
27 changes: 27 additions & 0 deletions packages/dai-plugin-mcd/src/PsmTypeService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PublicService } from '@makerdao/services-core';
import { ServiceRoles } from './constants';
import PsmType from './PsmType';

const { PSM_TYPE } = ServiceRoles;

export default class PsmService extends PublicService {
constructor(name = PSM_TYPE) {
super(name);
this.reset = this.resetAllPsmTypes;
}

initialize(settings = {}) {
this.settings = settings;
this.psmTypes = (settings.psmTypes || []).map(
psmType => new PsmType(this, psmType, { prefetch: settings.prefetch })
);
}

async connect() {
if (this.settings.prefetch) await this.prefetchAllCdpTypes();
}

async prefetchAllPsmTypes() {
await Promise.all(this.psmTypes.map(type => type.prefetch()));
}
}
2 changes: 1 addition & 1 deletion packages/dai-plugin-mcd/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const ServiceRoles = {
AUCTION: 'mcd:auction',
SYSTEM_DATA: 'mcd:systemData',
SAVINGS: 'mcd:savings',
PSM: 'mcd:psm'
PSM_TYPE: 'mcd:psmType'
};

export const WAD = new BigNumber('1e18');
Expand Down
28 changes: 24 additions & 4 deletions packages/dai-plugin-mcd/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ import SavingsService from './SavingsService';
import CdpTypeService from './CdpTypeService';
import AuctionService from './AuctionService';
import SystemDataService from './SystemDataService';
import PsmService from './PsmService';

import { ServiceRoles as ServiceRoles_ } from './constants';
import BigNumber from 'bignumber.js';
import wethAbi from '../contracts/abis/WETH9.json';

export const ServiceRoles = ServiceRoles_;
const { CDP_MANAGER, CDP_TYPE, SYSTEM_DATA, AUCTION, SAVINGS } = ServiceRoles;
const {
CDP_MANAGER,
CDP_TYPE,
SYSTEM_DATA,
AUCTION,
SAVINGS,
PSM_TYPE
} = 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 @@ -83,6 +92,10 @@ export const defaultCdpTypes = [
{ currency: ZRX, ilk: 'ZRX-A', decimals: 18 }
];

export const defaultPsmTypes = [
{ currency: USDC, ilk: 'PSM-USDC-A', decimals: 6 }
];

export const SAI = createCurrency('SAI');

export const ALLOWANCE_AMOUNT = BigNumber(
Expand All @@ -102,7 +115,12 @@ export const defaultTokens = [
export const McdPlugin = {
addConfig: (
_,
{ cdpTypes = defaultCdpTypes, addressOverrides, prefetch = true } = {}
{
cdpTypes = defaultCdpTypes,
psmTypes = defaultPsmTypes,
addressOverrides,
prefetch = true
} = {}
) => {
if (addressOverrides) {
addContracts = mapValues(addContracts, (contractDetails, name) => ({
Expand Down Expand Up @@ -141,13 +159,15 @@ export const McdPlugin = {
CDP_TYPE,
AUCTION,
SYSTEM_DATA,
SAVINGS
SAVINGS,
PSM_TYPE
],
[CDP_TYPE]: [CdpTypeService, { cdpTypes, prefetch }],
[CDP_MANAGER]: CdpManager,
[SAVINGS]: SavingsService,
[AUCTION]: AuctionService,
[SYSTEM_DATA]: SystemDataService
[SYSTEM_DATA]: SystemDataService,
[PSM_TYPE]: [PsmService, { psmTypes, prefetch }]
};
}
};
Expand Down

0 comments on commit 19c0247

Please sign in to comment.