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

Commit

Permalink
Enable lock and wipe for unowned cdps (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Padraic-O-Mhuiris authored Jul 17, 2019
1 parent a321e07 commit b179ac5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
33 changes: 33 additions & 0 deletions packages/dai-plugin-mcd/src/CdpManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ export default class CdpManager extends LocalService {
return this.proxyActions[method](...args);
}

@tracksTransactions
async lock(id, ilk, lockAmount, { promise }) {
await this.get('proxy').ensureProxy({ promise });
const isEth = ETH.isInstance(lockAmount);
const args = [
this._managerAddress,
this._adapterAddress(ilk),
id,
!isEth && lockAmount.toFixed('wei'),
{
dsProxy: true,
value: isEth ? lockAmount.toFixed('wei') : 0,
promise
}
].filter(x => x);

const method = `lock${isEth ? 'ETH' : 'Gem'}`;
return this.proxyActions[method](...args);
}

@tracksTransactionsWithOptions({ numArguments: 5 })
async wipeAndFree(id, ilk, wipeAmount = MDAI(0), freeAmount, { promise }) {
const isEth = ETH.isInstance(freeAmount);
Expand All @@ -140,6 +160,19 @@ export default class CdpManager extends LocalService {
);
}

@tracksTransactions
async wipe(id, wipeAmount, { promise }) {
return this.proxyActions.wipe(
...[
this._managerAddress,
this._adapterAddress('DAI'),
this.getIdBytes(id),
wipeAmount.toFixed('wei'),
{ dsProxy: true, promise }
].filter(x => x)
);
}

async getUrn(id) {
if (!this._getUrnPromises[id]) {
this._getUrnPromises[id] = this._manager.urns(id);
Expand Down
6 changes: 4 additions & 2 deletions packages/dai-plugin-mcd/src/ManagedCdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export default class ManagedCdp {
}

lockCollateral(amount, { promise } = {}) {
return this.lockAndDraw(amount, undefined, { promise });
amount = castAsCurrency(amount, this.currency);
return this._cdpManager.lock(this.id, this.ilk, amount, { promise });
}

drawDai(amount, { promise } = {}) {
Expand All @@ -192,7 +193,8 @@ export default class ManagedCdp {
}

wipeDai(amount, { promise } = {}) {
return this.wipeAndFree(amount, undefined, { promise });
amount = castAsCurrency(amount, MDAI);
return this._cdpManager.wipe(this.id, amount, { promise });
}

freeCollateral(amount, { promise } = {}) {
Expand Down
4 changes: 1 addition & 3 deletions packages/dai-plugin-mcd/test/ManagedCdp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ describe.each([

const wipe = cdp.wipeDai(0.5);
const wipeHandler = jest.fn((tx, state) => {
expect(tx.metadata.method).toBe(
`wipeAndFree${GEM == ETH ? 'ETH' : 'Gem'}`
);
expect(tx.metadata.method).toBe('wipe');
expect(state).toBe(txStates[wipeHandler.mock.calls.length - 1]);
});
txMgr.listen(wipe, wipeHandler);
Expand Down

0 comments on commit b179ac5

Please sign in to comment.