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

Commit

Permalink
Merge pull request #194 from makerdao/MIG-60-Old-Chief-Check
Browse files Browse the repository at this point in the history
[WIP] Mig 60 old chief check
  • Loading branch information
jparklev authored Dec 17, 2019
2 parents c6aaaa7 + 4c6c259 commit 78a88e8
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/dai-plugin-migrations/contracts/abiMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"REDEEMER": "Redeemer",
"MIGRATION": "ScdMcdMigration",
"MIGRATION_PROXY_ACTIONS": "MigrationProxyActions",
"OLD_CHIEF": "DSChief"
"OLD_CHIEF": "DSChief",
"OLD_VOTE_PROXY_FACTORY": "VoteProxyFactory"
}
102 changes: 102 additions & 0 deletions packages/dai-plugin-migrations/contracts/abis/VoteProxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
{
"constant": true,
"inputs": [],
"name": "gov",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "cold",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "freeAll",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "iou",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "slate", "type": "bytes32" }],
"name": "vote",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "wad", "type": "uint256" }],
"name": "free",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "wad", "type": "uint256" }],
"name": "lock",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "hot",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "name": "yays", "type": "address[]" }],
"name": "vote",
"outputs": [{ "name": "", "type": "bytes32" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "chief",
"outputs": [{ "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "name": "_chief", "type": "address" },
{ "name": "_cold", "type": "address" },
{ "name": "_hot", "type": "address" }
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"contract DSChief","name":"chief_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"cold","type":"address"},{"indexed":true,"internalType":"address","name":"hot","type":"address"},{"indexed":true,"internalType":"address","name":"voteProxy","type":"address"}],"name":"LinkConfirmed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"cold","type":"address"},{"indexed":true,"internalType":"address","name":"hot","type":"address"}],"name":"LinkRequested","type":"event"},{"constant":false,"inputs":[{"internalType":"address","name":"cold","type":"address"}],"name":"approveLink","outputs":[{"internalType":"contract VoteProxy","name":"voteProxy","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"breakLink","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"chief","outputs":[{"internalType":"contract DSChief","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"coldMap","outputs":[{"internalType":"contract VoteProxy","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"guy","type":"address"}],"name":"hasProxy","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"hotMap","outputs":[{"internalType":"contract VoteProxy","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"hot","type":"address"}],"name":"initiateLink","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"linkRequests","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"linkSelf","outputs":[{"internalType":"contract VoteProxy","name":"voteProxy","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"REDEEMER": "0x2c0f31271673cc29927be725104642aad65a253e",
"OLD_MKR": "0x4bb514a7f83fbb13c2b41448208e89fabbcfe2fb",
"MIGRATION": "0x411b2faa662c8e3e5cf8f01dfdae0aee482ca7b0",
"MIGRATION_PROXY_ACTIONS": "0xf56765d255463139d3aff1613705a5520764ab93"
"MIGRATION_PROXY_ACTIONS": "0xf56765d255463139d3aff1613705a5520764ab93",
"OLD_CHIEF": "0xbbffc76e94b34f72d96d054b31f6424249c1337d",
"OLD_VOTE_PROXY_FACTORY": "0x3E08741A68c2d964d172793cD0Ad14292F658cd8"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"CDP_MANAGER_1": "0x5ef30b9986345249bc32d8928b7ee64de9435e39",
"MCD_END_1": "0xab14d3ce3f733cacb76ec2abe7d2fcb00c99f3d5",
"MCD_VAT_1": "0x35d1b3f3d7966a1dfe207aa4514c12a259a0492b",
"MCD_DAI_1" : "0x6b175474e89094c44da98b954eedeac495271d0f",
"MCD_POT_1": "0x197e90f9fad81970ba7976f33cbd77088e5d7cf7"
"MCD_DAI_1": "0x6b175474e89094c44da98b954eedeac495271d0f",
"MCD_POT_1": "0x197e90f9fad81970ba7976f33cbd77088e5d7cf7",
"OLD_CHIEF": "0x8e2a84d6ade1e7fffee039a35ef5f19f13057152",
"OLD_VOTE_PROXY_FACTORY": "0xa63E145309cadaa6A903a19993868Ef7E85058BE"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"OLD_MKR": "0x1e1e0cb82b75fda8d3653bef925bf1babd160067",
"MIGRATION": "0x1f8d3148c725de9d31751c9f8cb764c8ee6d9719",
"MIGRATION_PROXY_ACTIONS": "0x5f295c5589118d2f8eab6488c366d42c0f54882c",
"OLD_CHIEF": "0xe50ff8544b50e2e0f25cab27bc85a7a905d5671a"
"OLD_CHIEF": "0xe50ff8544b50e2e0f25cab27bc85a7a905d5671a",
"OLD_VOTE_PROXY_FACTORY": "0x17d4edea99fad126ce0b3ed46646587d067f4f8c"
}
11 changes: 10 additions & 1 deletion packages/dai-plugin-migrations/src/MigrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import GlobalSettlementDaiRedeemer from './migrations/GlobalSettlementDaiRedeeme
import SaiToDai from './migrations/SaiToDai';
import MkrRedeemer from './migrations/MkrRedeemer';
import DaiToSai from './migrations/DaiToSai';
const { SINGLE_TO_MULTI_CDP, SAI_TO_DAI, DAI_TO_SAI, MKR_REDEEMER } = Migrations;
import ChiefMigrate from './migrations/ChiefMigrate';
const {
SINGLE_TO_MULTI_CDP,
SAI_TO_DAI,
DAI_TO_SAI,
MKR_REDEEMER,
CHIEF_MIGRATE
} = Migrations;

const migrations = {
[SINGLE_TO_MULTI_CDP]: SingleToMultiCdp,
[SAI_TO_DAI]: SaiToDai,
[DAI_TO_SAI]: DaiToSai,
[CHIEF_MIGRATE]: ChiefMigrate,
[Migrations.GLOBAL_SETTLEMENT_SAVINGS_DAI]: GlobalSettlementSavingsDai,
[Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: GlobalSettlementCollateralClaims,
[Migrations.GLOBAL_SETTLEMENT_DAI_REDEEMER]: GlobalSettlementDaiRedeemer,
Expand Down Expand Up @@ -49,6 +57,7 @@ export default class MigrationService extends PublicService {
).check(),
[SAI_TO_DAI]: await this.getMigration(SAI_TO_DAI).check(),
[DAI_TO_SAI]: await this.getMigration(DAI_TO_SAI).check(),
[CHIEF_MIGRATE]: await this.getMigration(CHIEF_MIGRATE).check(),
[MKR_REDEEMER]: await this.getMigration(MKR_REDEEMER).check()
};
}
Expand Down
3 changes: 2 additions & 1 deletion packages/dai-plugin-migrations/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const Migrations = {
GLOBAL_SETTLEMENT_SAVINGS_DAI: 'global-settlement-savings-dai',
GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS: 'global-settlement-collateral-claims',
GLOBAL_SETTLEMENT_DAI_REDEEMER: 'global-settlement-dai-redeemer',
MKR_REDEEMER: 'mkr-redeemer'
MKR_REDEEMER: 'mkr-redeemer',
CHIEF_MIGRATE: 'chief-migrate'
};

export const WAD = new BigNumber('1e18');
Expand Down
37 changes: 37 additions & 0 deletions packages/dai-plugin-migrations/src/migrations/ChiefMigrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { MKR } from '..';

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

export default class ChiefMigrate {
constructor(manager) {
this._manager = manager;
this._oldChief = manager.get('smartContract').getContract('OLD_CHIEF');
this._oldProxyFactoryContract = manager
.get('smartContract')
.getContractByName('OLD_VOTE_PROXY_FACTORY');
return this;
}

async check() {
const address = this._manager.get('accounts').currentAddress();
const voteProxyAddress = await this._getVoteProxyAddress(address);

const mkrLockedDirectly = MKR.wei(await this._oldChief.deposits(address));
const mkrLockedViaProxy = MKR.wei(
voteProxyAddress ? await this._oldChief.deposits(voteProxyAddress) : 0
);

return { mkrLockedDirectly, mkrLockedViaProxy };
}

async _getVoteProxyAddress(walletAddress) {
const [proxyAddressCold, proxyAddressHot] = await Promise.all([
this._oldProxyFactoryContract.coldMap(walletAddress),
this._oldProxyFactoryContract.hotMap(walletAddress)
]);

if (proxyAddressCold !== ZERO_ADDRESS) return proxyAddressCold;
if (proxyAddressHot !== ZERO_ADDRESS) return proxyAddressHot;
return null;
}
}
10 changes: 6 additions & 4 deletions packages/dai-plugin-migrations/test/MigrationService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ test('can fetch a list of all migrations', () => {
Migrations.GLOBAL_SETTLEMENT_SAVINGS_DAI,
Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS,
Migrations.GLOBAL_SETTLEMENT_DAI_REDEEMER,
Migrations.MKR_REDEEMER
Migrations.MKR_REDEEMER,
Migrations.CHIEF_MIGRATE
])
);
expect(ids.length).toEqual(7);
expect(ids.length).toEqual(8);
});

test('getting each migration returns a valid migration', () => {
Expand Down Expand Up @@ -75,8 +76,9 @@ test('runAllChecks', async () => {
expect(result).toEqual({
[Migrations.SAI_TO_DAI]: expect.anything(),
[Migrations.DAI_TO_SAI]: expect.anything(),
[Migrations.MKR_REDEEMER]: expect.anything(),
[Migrations.SINGLE_TO_MULTI_CDP]: {}
[Migrations.SINGLE_TO_MULTI_CDP]: {},
[Migrations.CHIEF_MIGRATE]: expect.anything(),
[Migrations.MKR_REDEEMER]: expect.anything()
});
expect(result[Migrations.SAI_TO_DAI].eq(0)).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { migrationMaker } from '../helpers';
import { ServiceRoles, Migrations } from '../../src/constants';
import {
takeSnapshot,
restoreSnapshot,
TestAccountProvider
} from '@makerdao/test-helpers';
import { MKR } from '../../src';
import voteProxyAbi from '../../contracts/abis/VoteProxy.json';

let maker, migration, snapshot;

describe('Chief Migration', () => {
beforeAll(async () => {
maker = await migrationMaker();
const service = maker.service(ServiceRoles.MIGRATION);
migration = service.getMigration(Migrations.CHIEF_MIGRATE);
});

beforeEach(async () => {
snapshot = await takeSnapshot(maker);
});

afterEach(() => {
restoreSnapshot(snapshot, maker);
});

test('if the account has no MKR locked in old chief, return 0', async () => {
const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check();
expect(mkrLockedDirectly.toNumber()).toBe(0);
expect(mkrLockedViaProxy.toNumber()).toBe(0);
});

test('if the account has some MKR locked directly in old chief, return the amount', async () => {
const oldChief = maker
.service('smartContract')
.getContractByName('OLD_CHIEF');

await maker
.service('token')
.getToken(MKR)
.approveUnlimited(oldChief.address);

const LOCK_AMOUNT = MKR('5.123456789123456789');
await oldChief.lock(LOCK_AMOUNT.toFixed('wei'));

const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check();
expect(mkrLockedDirectly.isEqual(LOCK_AMOUNT)).toBeTruthy();
expect(mkrLockedViaProxy.toNumber()).toBe(0);
});

test('if the account has some MKR locked via proxy in old chief, return the amount', async () => {
const oldVoteProxyFactory = maker
.service('smartContract')
.getContractByName('OLD_VOTE_PROXY_FACTORY');

const coldAccount = maker.currentAccount();
const hotAccount = TestAccountProvider.nextAccount();
await maker.addAccount({ ...hotAccount, type: 'privateKey' });

// initiate from cold
maker.useAccount('default');
await oldVoteProxyFactory.initiateLink(hotAccount.address);

// switch to hot
maker.useAccount(hotAccount.address);
await oldVoteProxyFactory.approveLink(coldAccount.address);

// and back to cold
maker.useAccount('default');
const voteProxyAddress = await migration._getVoteProxyAddress(
coldAccount.address
);

const voteProxy = maker
.service('smartContract')
.getContractByAddressAndAbi(voteProxyAddress, voteProxyAbi);

await maker
.service('token')
.getToken(MKR)
.approveUnlimited(voteProxyAddress);

const LOCK_AMOUNT = MKR('5.123456789123456789');
await voteProxy.lock(LOCK_AMOUNT.toFixed('wei'));

const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check();
expect(mkrLockedDirectly.toNumber()).toBe(0);
expect(mkrLockedViaProxy.isEqual(LOCK_AMOUNT)).toBeTruthy();
});
});

0 comments on commit 78a88e8

Please sign in to comment.