This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from makerdao/MIG-60-Old-Chief-Check
[WIP] Mig 60 old chief check
- Loading branch information
Showing
11 changed files
with
260 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/dai-plugin-migrations/contracts/abis/VoteProxy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
packages/dai-plugin-migrations/contracts/abis/VoteProxyFactory.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/dai-plugin-migrations/src/migrations/ChiefMigrate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |