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

Commit

Permalink
Merge branch 'pay-with-debt' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbennett committed Nov 13, 2019
2 parents fae75df + 76db7b2 commit 7f62501
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 25 deletions.
28 changes: 16 additions & 12 deletions packages/dai-plugin-migrations/src/migrations/SingleToMultiCdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class SingleToMultiCdp {
}

@tracksTransactionsWithOptions({ numArguments: 4 })
async execute(cupId, payment = 'MKR', maxPayAmount, { promise }) {
async execute(cupId, payment = 'MKR', maxPayAmount, minRatio, { promise }) {
const migrationProxy = this._manager
.get('smartContract')
.getContract('MIGRATION_PROXY_ACTIONS');
Expand All @@ -32,7 +32,8 @@ export default class SingleToMultiCdp {
const { method, args } = this._setMethodAndArgs(
payment,
defaultArgs,
maxPayAmount
maxPayAmount,
minRatio
);

await this._requireAllowance(cupId);
Expand All @@ -54,13 +55,11 @@ export default class SingleToMultiCdp {
if (allowance.lt(fee)) await mkr.approve(proxyAddress, fee.times(1.5));
}

// eslint-disable-next-line
_setMethodAndArgs(payment, defaultArgs, maxPayAmount) {
// eslint-disable-next-line
_setMethodAndArgs(payment, defaultArgs, maxPayAmount, minRatio) {
const otc = this._manager.get('smartContract').getContract('MAKER_OTC')
.address;

// to do:
// to-do:
// if (payment === 'GEM') {
// const gem = this._manager
// .get('token')
Expand All @@ -72,12 +71,17 @@ export default class SingleToMultiCdp {
// };
// }

// if (payment === 'DEBT') {
// return {
// method: 'migratePayFeeWithDebt',
// args: [...defaultArgs, otc, SAI(maxPayAmount).toFixed('wei')]
// };
// }
if (payment === 'DEBT') {
return {
method: 'migratePayFeeWithDebt',
args: [
...defaultArgs,
otc,
SAI(maxPayAmount).toFixed('wei'),
SAI(minRatio).toFixed('wei')
]
};
}

return {
method: 'migrate',
Expand Down
46 changes: 46 additions & 0 deletions packages/dai-plugin-migrations/test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import McdPlugin, {
USD
} from '@makerdao/dai-plugin-mcd';
import ethAbi from 'web3-eth-abi';
import { utils } from 'ethers';

export function stringToBytes(str) {
return '0x' + Buffer.from(str).toString('hex');
Expand Down Expand Up @@ -69,3 +70,48 @@ export async function migrationMaker({
await maker.authenticate();
return maker;
}

export async function placeLimitOrder(migrationService) {
const daiToken = migrationService.get('token').getToken('DAI');
const daiAddress = daiToken.address();
const oasisAddress = migrationService
.get('smartContract')
.getContractByName('MAKER_OTC').address;
const mkrToken = migrationService.get('token').getToken('MKR');
const mkrAddress = mkrToken.address();
const value = utils.parseEther('10.0');

await mkrToken.approveUnlimited(oasisAddress);
await daiToken.approveUnlimited(oasisAddress);

return await offer(
migrationService,
utils.parseEther('0.5'),
mkrAddress,
value,
daiAddress,
1
);
}

async function offer(
migrationService,
payAmount,
payTokenAddress,
buyAmount,
buyTokenAddress,
position
) {
const oasisContract = migrationService
.get('smartContract')
.getContractByName('MAKER_OTC');

const tx = await oasisContract.offer(
payAmount,
payTokenAddress,
buyAmount,
buyTokenAddress,
position
);
return await tx.mine();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrationMaker } from '../helpers';
import { migrationMaker, placeLimitOrder } from '../helpers';
import { mockCdpIds } from '../helpers/mocks';
import { ServiceRoles, Migrations } from '../../src/constants';
import {
Expand Down Expand Up @@ -93,7 +93,11 @@ describe('SCD to MCD CDP Migration', () => {
});
});

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

beforeEach(async () => {
Expand All @@ -108,9 +112,16 @@ describe('SCD to MCD CDP Migration', () => {
await restoreSnapshot(snapshotData, maker);
});

test('migrate scd cdp to mcd, pay fee with mkr', async () => {
const manager = maker.service('mcd:cdpManager');
test('execute', async () => {
let maxPayAmount, minRatio;

if (payment !== 'MKR') {
await placeLimitOrder(migration._manager);
maxPayAmount = 10;
}
if (payment === 'DEBT') minRatio = 150;

const manager = maker.service('mcd:cdpManager');
const scdCollateral = await cdp.getCollateralValue();
const scdDebt = await cdp.getDebtValue();
await mineBlocks(maker.service('web3'), 3);
Expand All @@ -121,7 +132,12 @@ describe('SCD to MCD CDP Migration', () => {

const mcdCdpsBeforeMigration = await manager.getCdpIds(proxyAddress);

const newId = await migration.execute(cdp.id);
const newId = await migration.execute(
cdp.id,
payment,
maxPayAmount,
minRatio
);
await manager.reset();

const mcdCdpsAfterMigration = await manager.getCdpIds(proxyAddress);
Expand All @@ -147,14 +163,6 @@ describe('SCD to MCD CDP Migration', () => {
expect(mcdCdpsAfterMigration.length).toEqual(
mcdCdpsBeforeMigration.length + 1
);
}, 15000);

xtest('migrate scd cdp to mcd, pay fee with sai', async () => {
// await migration.execute(cdp.id, 'GEM', 10);
});

xtest('migrate scd cdp to mcd, pay fee with debt', async () => {
// await migration.execute(cdp.id, 'DEBT', 10);
});
});
});

0 comments on commit 7f62501

Please sign in to comment.