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

Commit

Permalink
Fix sai allowance in cdp migration/payFeeWithGem option
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbennett committed Nov 15, 2019
1 parent a4d0488 commit bd4b759
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/dai-plugin-migrations/src/MigrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class MigrationService extends PublicService {
'token',
'web3',
'mcd:cdpManager',
'mcd:cdpType'
'mcd:cdpType',
'price'
]);
}

Expand Down
31 changes: 17 additions & 14 deletions packages/dai-plugin-migrations/src/migrations/SingleToMultiCdp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tracksTransactionsWithOptions } from '@makerdao/dai/dist/src/utils/tracksTransactions';
import { getIdBytes, stringToBytes } from '../utils';
import { SAI, MKR, DAI } from '..';
import { SAI, MKR } from '..';

export default class SingleToMultiCdp {
constructor(manager) {
Expand Down Expand Up @@ -44,11 +44,15 @@ export default class SingleToMultiCdp {
const address = this._manager.get('web3').currentAddress();
const proxyAddress = await this._manager.get('proxy').currentProxy();
const cdp = await this._manager.get('cdp').getCdp(cupId);
// fee value needs to be converted to dai if payment === 'GEM'
const fee = await cdp.getGovernanceFee();
const token = payment === 'MKR'
? this._getToken(MKR)
: this._getToken(SAI);

let fee = await cdp.getGovernanceFee();
if (payment === 'GEM') {
const mkrPrice = await this._manager.get('price').getMkrPrice();
fee = SAI(fee.toNumber() * mkrPrice.toNumber());
}
const allowance = await token.allowance(address, proxyAddress);

// add a buffer amount to allowance in case drip hasn't been called recently
Expand All @@ -59,17 +63,16 @@ export default class SingleToMultiCdp {
const otc = this._manager.get('smartContract').getContract('MAKER_OTC')
.address;

// to-do:
// if (payment === 'GEM') {
// const gem = this._manager
// .get('token')
// .getToken('DAI')
// .address();
// return {
// method: 'migratePayFeeWithGem',
// args: [...defaultArgs, otc, gem, SAI(maxPayAmount).toFixed('wei')]
// };
// }
if (payment === 'GEM') {
const gem = this._manager
.get('token')
.getToken('DAI')
.address();
return {
method: 'migratePayFeeWithGem',
args: [...defaultArgs, otc, gem, SAI(maxPayAmount).toFixed('wei')]
};
}

if (payment === 'DEBT') {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ describe('SCD to MCD CDP Migration', () => {

describe.each([
'MKR',
'DEBT'
// 'GEM'
'DEBT',
'GEM'
])('pay with %s', payment => {
let cdp, proxyAddress;

Expand All @@ -127,6 +127,7 @@ describe('SCD to MCD CDP Migration', () => {
maxPayAmount = 10;
}
if (payment === 'DEBT') minRatio = 150;
await maker.service('price').setMkrPrice(100);

const manager = maker.service('mcd:cdpManager');
const scdCollateral = await cdp.getCollateralValue();
Expand Down

0 comments on commit bd4b759

Please sign in to comment.