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

Commit

Permalink
Updatge maker
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinskipg committed Oct 15, 2021
1 parent cf933a5 commit 2af6bf8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/dai-plugin-liquidations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"bignumber.js": "^8.1.1",
"ramda": "^0.27.1"
},
"gitHead": "035aa87023c84916295cd4a2735cb2f6fdb1506e"
"gitHead": "cf933a533d6f0e5d5341facfcb2bfc290f3151c6"
}
95 changes: 62 additions & 33 deletions packages/dai/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,6 @@ export class MakerClass {
}

if (otherOptions.autoAuthenticate !== false) this.authenticate();

delegateToServices(this, {
accounts: [
'addAccount',
'currentAccount',
'currentAddress',
'listAccounts',
'useAccount',
'useAccountWithAddress'
],
cdp: ['getCdp', 'openCdp', 'getCdpIds'],
event: ['on'],
proxy: ['currentProxy'],
token: ['getToken'],
multicall: ['watch', 'latest']
});
}

authenticate() {
Expand All @@ -67,6 +51,68 @@ export class MakerClass {
return this._authenticatedPromise;
}

// shorthand methods
addAccount(...args) {
return this.service('accounts').addAccount(...args);
}

currentAccount(...args) {
return this.service('accounts').currentAccount(...args);
}

listAccounts(...args) {
return this.service('accounts').listAccounts(...args);
}

useAccount(...args) {
return this.service('accounts').useAccount(...args);
}

useAccountWithAddress(...args) {
return this.service('accounts').useAccountWithAddress(...args);
}

currentAddress(...args) {
return this.service('accounts').currentAddress(...args);
}

on(...args) {
return this.service('event').on(...args);
}

getToken(...args) {
return this.service('token').getToken(...args);
}

currentProxy(...args) {
return this.service('proxy').currentProxy(...args);
}

watch(...args) {
return this.service('multicall').watch(...args);
}

latest(...args) {
return this.service('multicall').latest(...args);
}

openCdp() {
throw new Error(
'"openCdp" is no longer available here. Add @makerdao/dai-plugin-scd, then use maker.service(\'cdp\').openCdp'
);
}

getCdp() {
throw new Error(
'"getCdp" is no longer available here. Add @makerdao/dai-plugin-scd, then use maker.service(\'cdp\').getCdp'
);
}

getCdpIds() {
throw new Error(
'"getCdpIds" is no longer available here. Add @makerdao/dai-plugin-scd, then use maker.service(\'cdp\').getCdpIds'
);
}
// skipAuthCheck should only be set if you're sure you don't need the service
// to be initialized yet, e.g. when setting up a plugin
service(service, skipAuthCheck = false) {
Expand All @@ -84,23 +130,6 @@ export class MakerClass {
}
}

function delegateToServices(maker, services) {
for (const serviceName in services) {
for (const methodName of services[serviceName]) {
if (serviceName === 'cdp') {
maker[methodName] = () => {
throw new Error(
`"${methodName}" is no longer available here. Add @makerdao/dai-plugin-scd, then use maker.service('cdp').${methodName}`
);
};
} else {
maker[methodName] = (...args) =>
maker.service(serviceName)[methodName](...args);
}
}
}
}

function mergeOptions(object, source) {
return mergeWith(object, source, (objValue, srcValue, key) => {
if (Array.isArray(objValue) && key === 'abi') return uniq(objValue);
Expand Down

0 comments on commit 2af6bf8

Please sign in to comment.