Skip to content

Commit

Permalink
Cleanup migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
petejkim committed May 12, 2020
1 parent 9771630 commit 626553f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DOCROOT="$( cd "$( dirname "$0" )" && pwd )"
docker-compose -f $DOCROOT/docker-compose.yml run --rm truffle compile

# run solidity tests
docker-compose -f $DOCROOT/docker-compose.yml run --rm truffle --network localTestNet test
docker-compose -f $DOCROOT/docker-compose.yml run --rm truffle --network local_testnet test

#stop containers
docker-compose -f $DOCROOT/docker-compose.yml down
4 changes: 2 additions & 2 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Migrations = artifacts.require("./Migrations.sol");

module.exports = function (deployer) {
deployer.deploy(Migrations);
module.exports = async (deployer) => {
await deployer.deploy(Migrations);
};
144 changes: 79 additions & 65 deletions migrations/2_deploy_usdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,87 @@ const FiatTokenProxy = artifacts.require("./FiatTokenProxy.sol");
// Any address will do, preferably one we generated
const throwawayAddress = "0x64e078a8aa15a41b85890265648e965de686bae6";

module.exports = function (deployer, network) {
if (network === "mainnet") {
throw new Error("Please update 2_deploy_usdc.js and remove this line.");
module.exports = async (deployer, network) => {
let admin, masterMinter, pauser, blacklister, owner;

if (network.toLowerCase().includes("mainnet")) {
const {
ADMIN_ADDRESS,
MASTERMINTER_ADDRESS,
PAUSER_ADDRESS,
BLACKLISTER_ADDRESS,
OWNER_ADDDRESS,
} = process.env;

if (
!ADMIN_ADDRESS ||
!MASTERMINTER_ADDRESS ||
!PAUSER_ADDRESS ||
!BLACKLISTER_ADDRESS ||
!OWNER_ADDDRESS
) {
throw new Error(
"Env vars ADMIN_ADDRESS, MASTERMINTER_ADDRESS, PAUSER_ADDRESS, " +
"BLACKLISTER_ADDRESS, and OWNER_ADDRESS must be defined for " +
"mainnet deployment"
);
}

admin = ADMIN_ADDRESS;
masterMinter = MASTERMINTER_ADDRESS;
pauser = PAUSER_ADDRESS;
blacklister = BLACKLISTER_ADDRESS;
owner = OWNER_ADDDRESS;
} else {
// Do not use these addresses for mainnet - these are the deterministic
// addresses from ganache, so the private keys are well known and match the
// values we use in the tests
admin = "0x2F560290FEF1B3Ada194b6aA9c40aa71f8e95598";
masterMinter = "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9";
pauser = "0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E";
blacklister = "0xd03ea8624C8C5987235048901fB614fDcA89b117";
owner = "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d";
}

// Change these to the cold storage addresses provided by ops
// these are the deterministic addresses from ganache, so the private keys are well known
// and match the values we use in the tests
const admin = "0x2F560290FEF1B3Ada194b6aA9c40aa71f8e95598";
const masterMinter = "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9";
const pauser = "0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E";
const blacklister = "0xd03ea8624C8C5987235048901fB614fDcA89b117";
const owner = "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d";
console.log("Deploying implementation contract...");
await deployer.deploy(FiatTokenV1);
const fiatTokenV1 = await FiatTokenV1.deployed();
console.log("Deployed implementation contract at", FiatTokenV1.address);

console.log("deploying impl");
console.log("Initializing implementation contract with dummy values...");
await fiatTokenV1.initialize(
"",
"",
"",
0,
throwawayAddress,
throwawayAddress,
throwawayAddress,
throwawayAddress
);

// deploy implementation contract
deployer
.deploy(FiatTokenV1)
.then(function () {
return FiatTokenV1.deployed();
})
.then(function (fiatTokenV1) {
console.log("initializing impl with dummy values");
return fiatTokenV1.initialize(
"",
"",
"",
0,
throwawayAddress,
throwawayAddress,
throwawayAddress,
throwawayAddress
);
})
.then(function () {
console.log("deploying proxy");
return deployer.deploy(FiatTokenProxy, FiatTokenV1.address);
})
.then(function () {
return FiatTokenProxy.deployed();
})
.then(function (fiatTokenProxy) {
console.log("reassigning proxy admin");
// need to change admin first, or the call to initialize won't work
// since admin can only call methods in the proxy, and not forwarded methods
return fiatTokenProxy.changeAdmin(admin);
})
.then(function () {
return FiatTokenV1.at(FiatTokenProxy.address);
})
.then(function (fiatTokenProxyAsFiatTokenV1) {
console.log("initializing proxy");
// Pretend that the proxy address is a FiatTokenV1
// this is fine because the proxy will forward all the calls to the FiatTokenV1 impl
return fiatTokenProxyAsFiatTokenV1.initialize(
"USD//C",
"USDC",
"USD",
6,
masterMinter,
pauser,
blacklister,
owner
);
})
.then(function () {
console.log("deployed proxy at ", FiatTokenProxy.address);
});
console.log("Deploying proxy contract...");
await deployer.deploy(FiatTokenProxy, FiatTokenV1.address);
const fiatTokenProxy = await FiatTokenProxy.deployed();
console.log("Deployed proxy contract at", FiatTokenProxy.address);

console.log("Reassigning proxy contract admin...");
// need to change admin first, or the call to initialize won't work
// since admin can only call methods in the proxy, and not forwarded methods
await fiatTokenProxy.changeAdmin(admin);

console.log("Initializing proxy contract...");
const fiatTokenV1Proxied = await FiatTokenV1.at(FiatTokenProxy.address);
// Pretend that the proxy address is a FiatTokenV1 - this is fine because the
// proxy will forward all the calls to the FiatTokenV1 impl
await fiatTokenV1Proxied.initialize(
"USD//C",
"USDC",
"USD",
6,
masterMinter,
pauser,
blacklister,
owner
);
};
3 changes: 1 addition & 2 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ module.exports = {
port: 8545,
network_id: "*", // Match any network id
},
// network to refer to ganache by name so it works with truffle/ganache in separate docker containers
localTestNet: {
local_testnet: {
host: "ganache",
port: 8545,
network_id: "*", // Match any network id
Expand Down

0 comments on commit 626553f

Please sign in to comment.