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

Commit

Permalink
simplify dai-plugin-migrations config
Browse files Browse the repository at this point in the history
  • Loading branch information
levity committed Dec 18, 2019
1 parent 78a88e8 commit d8c8fb4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 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 @@ -10,5 +10,6 @@
"MIGRATION": "ScdMcdMigration",
"MIGRATION_PROXY_ACTIONS": "MigrationProxyActions",
"OLD_CHIEF": "DSChief",
"OLD_VOTE_PROXY_FACTORY": "VoteProxyFactory"
"OLD_VOTE_PROXY_FACTORY": "VoteProxyFactory",
"OLD_MKR": "DSToken"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"MCD_POT_1": "0x1fbf51a780232f0cf01195d7021e1bb76612462a",
"REDEEMER": "0x396c36f467e6db6c14722e02605d31e9198ae7cf",
"OLD_MKR": "0x1e1e0cb82b75fda8d3653bef925bf1babd160067",
"MIGRATION": "0x1f8d3148c725de9d31751c9f8cb764c8ee6d9719",
"MIGRATION_PROXY_ACTIONS": "0x5f295c5589118d2f8eab6488c366d42c0f54882c",
"OLD_CHIEF": "0xe50ff8544b50e2e0f25cab27bc85a7a905d5671a",
"OLD_VOTE_PROXY_FACTORY": "0x17d4edea99fad126ce0b3ed46646587d067f4f8c"
}
38 changes: 10 additions & 28 deletions packages/dai-plugin-migrations/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ export const SAI = createCurrency('DAI');
export const DAI = createCurrency('MDAI');
export const MKR = createCurrency('MKR');

function overrideContractAddresses(network, addressOverrides, contracts) {
function overrideContractAddresses(addressOverrides, contracts) {
Object.entries(addressOverrides).forEach(([name, overrideAddress]) => {
if (contracts[name]) {
contracts[name] = {
...contracts[name],
address: {
[network]: overrideAddress || contracts[name].address[network]
}
};
contracts[name] = { ...contracts[name], address: overrideAddress };
}
});

Expand All @@ -52,34 +47,21 @@ function overrideContractAddresses(network, addressOverrides, contracts) {
export const MDAI_1 = createCurrency('MDAI_1');

export default {
addConfig: (_, { network = 'mainnet', addressOverrides } = {}) => {
const oldMkrData = {
currency: OLD_MKR,
abi: require('../contracts/abis/DSToken.json'),
address: require(`../contracts/addresses/${network}.json`).OLD_MKR,
decimals: 18
};

addConfig: (_, { addressOverrides } = {}) => {
const addContracts = addressOverrides
? overrideContractAddresses(network, addressOverrides, allContracts)
? overrideContractAddresses(addressOverrides, allContracts)
: allContracts;

// remove contracts that don't have an address for the given network
for (let c of Object.keys(addContracts)) {
if (
typeof addContracts[c].address === 'object' &&
!addContracts[c].address[network]
) {
delete addContracts[c];
}
}

return {
smartContract: { addContracts },
token: {
erc20: [
oldMkrData,
{ currency: MDAI_1, address: addContracts.MCD_DAI_1.address[network] }
{
currency: OLD_MKR,
decimals: 18,
address: addContracts.OLD_MKR.address
},
{ currency: MDAI_1, address: addContracts.MCD_DAI_1.address }
]
},
additionalServices: [MIGRATION],
Expand Down

0 comments on commit d8c8fb4

Please sign in to comment.