This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecc1b88
commit 19c0247
Showing
6 changed files
with
93 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters