Skip to content

Commit

Permalink
deploy new TokenAEur and all dependent contracts to Rinkeby
Browse files Browse the repository at this point in the history
  • Loading branch information
szerintedmi committed May 12, 2018
1 parent 7241223 commit 3620d07
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 5 deletions.
15 changes: 14 additions & 1 deletion abiniser/deployments/4/Exchange_DEPLOYS.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion abiniser/deployments/4/LoanManager_DEPLOYS.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion abiniser/deployments/4/Locker_DEPLOYS.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion abiniser/deployments/4/MonetarySupervisor_DEPLOYS.json

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion abiniser/deployments/4/TokenAEur_DEPLOYS.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contractName": "TokenAEur",
"latestAbiHash": "d7dd02520f2d92b2ca237f066cf2488d",
"latestAbiHash": "4b49e7e6d1a9a2de81a4d2d088acbc04",
"deployedAbis": {
"27721a2c77dc40da7639abd46791c3d7": {
"latestDeployedAddress": "0x95aa79d7410eb60f49bfd570b445836d402bd7b1",
Expand Down Expand Up @@ -53,6 +53,24 @@
"source": "/* Augmint Crypto Euro token (ACE) implementation */\npragma solidity ^0.4.23;\nimport \"./interfaces/TransferFeeInterface.sol\";\nimport \"./generic/AugmintToken.sol\";\n\n\ncontract TokenAEur is AugmintToken {\n constructor(TransferFeeInterface _feeAccount)\n public AugmintToken(\"Augmint Crypto Euro\", \"AEUR\", \"EUR\", 2, _feeAccount)\n {} // solhint-disable-line no-empty-blocks\n\n}\n"
}
}
},
"4b49e7e6d1a9a2de81a4d2d088acbc04": {
"latestDeployedAddress": "0x6c90c10d7a33815c2baeed66ee8b848f1d95268e",
"deployments": {
"0x6c90c10d7a33815c2baeed66ee8b848f1d95268e": {
"generatedAt": "2018-05-12T01:34:38.456Z",
"truffleContractFileUpdatedAt": "2018-05-12T01:30:50.031Z",
"deployTransactionHash": "0xf45e9817fca468b5438d7a00a6461fd47e14cf04f1bb4b36ccc7302284ec39c5",
"compiler": {
"name": "solc",
"version": "0.4.23+commit.124ca40d.Emscripten.clang"
},
"bytecodeHash": "042675fc70cfed8762b1e7de8d15799f",
"deployedBytecodeHash": "03b0c0d8c49d83af34516ac82bc0b2a9",
"sourceHash": "61dded7836f4431e621382340f32670c",
"source": "/* Augmint Crypto Euro token (ACE) implementation */\npragma solidity ^0.4.23;\nimport \"./interfaces/TransferFeeInterface.sol\";\nimport \"./generic/AugmintToken.sol\";\n\n\ncontract TokenAEur is AugmintToken {\n constructor(TransferFeeInterface _feeAccount)\n public AugmintToken(\"Augmint Crypto Euro\", \"AEUR\", \"EUR\", 2, _feeAccount)\n {} // solhint-disable-line no-empty-blocks\n\n}\n"
}
}
}
}
}
181 changes: 181 additions & 0 deletions rinkeby_migrations/17_new_TokenAEur.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/* deploy new TokenAEur version and all dependent contracts:
- MonetarySupervisor (and switch over to it )
- Locker
- LoanManager
- Exchange
*/
const Migrations = artifacts.require("./Migrations.sol");
const TokenAEur = artifacts.require("./TokenAEur.sol");
const FeeAccount = artifacts.require("./FeeAccount.sol");
const Exchange = artifacts.require("./Exchange.sol");
const MonetarySupervisor = artifacts.require("./MonetarySupervisor.sol");
const InterestEarnedAccount = artifacts.require("./InterestEarnedAccount.sol");
const AugmintReserves = artifacts.require("./AugmintReserves.sol");
const Locker = artifacts.require("./Locker.sol");
const LoanManager = artifacts.require("./LoanManager.sol");

module.exports = function(deployer, network, accounts) {
const ratesAddress = "0xcA8100FCcb479516A5b30f8Bc5dAeA09Fb7a7473";

This comment has been minimized.

Copy link
@phraktle

phraktle May 14, 2018

Collaborator

Instead of hardcoding, could we pull these from an abiniser environment json instead? It would be reasonable to say something like “the FeeAccount from the early May rinkeby environment”.

This comment has been minimized.

Copy link
@szerintedmi

szerintedmi May 14, 2018

Author Member

how do you envision referencing to the corresponding deployment? Latest deployment at the moment of running the script?
If so then it might be difficult to retrospectively see which specific deployment it was ran at.
Or do you envision some kind of tagging of deployments?

This comment has been minimized.

Copy link
@phraktle

phraktle May 15, 2018

Collaborator

An environment could serve as a tag (it’s basically just a named collection of addresses).

This comment has been minimized.

Copy link
@szerintedmi

szerintedmi May 16, 2018

Author Member

I'm not convinced (or just don't understand your suggestion properly) that would be better. In practice it wasn't a big deal (nor caused any errors) to copy-paste the current contract addresses when writing a migration step. In the other hand auditing a migration step retrospectively is much easier with addresses - don't need to go back in git history and dig into the abiniser jsons to see which contract address was the live one at the moment of running the migration script.
do I miss a point?

const feeAccount = FeeAccount.at("0xc26667132b0B798ab87864f7c29c0819c887aADB");
const augmintReserves = AugmintReserves.at("0xc70b65e40f877cdC6d8D2ebFd44d63EfBeb7fc6D");
const interestEarnedAccount = InterestEarnedAccount.at("0x3a414d7636defb9d3dfb7342984fe3f7b5125df6");
const oldMonetarySupervisor = MonetarySupervisor.at("0xa00a5d1882C3F690E3d0D975ebE378120b70ae87");

const oldToken1 = TokenAEur.at("0x95aa79d7410eb60f49bfd570b445836d402bd7b1");
const oldToken2 = TokenAEur.at("0xa35d9de06895a3a2e7ecae26654b88fe71c179ea");
const oldToken3 = TokenAEur.at("0x135893F1A6B3037BB45182841f18F69327366992");

const oldLocker1 = Locker.at("0xf98AE1fb568B267A7632BF54579A153C892E2ec2");
const oldLoanManager1 = LoanManager.at("0xBdb02f82d7Ad574f9F549895caf41E23a8981b07");

deployer.deploy(TokenAEur, feeAccount.address);

deployer.then(async () => {
/*************************************************************
* Deploy new TokenAEur
**************************************************************/

const newTokenAEur = TokenAEur.at(TokenAEur.address);

/*************************************************************
* Deploy new Exchange
**************************************************************/
await deployer.deploy(Exchange, newTokenAEur.address, ratesAddress);
const newExchange = Exchange.at(Exchange.address);

await feeAccount.grantPermission(newExchange.address, "NoFeeTransferContracts");

/*************************************************************
* Deploy new MonetarySupervisor
**************************************************************/
await deployer.deploy(
MonetarySupervisor,
newTokenAEur.address,
augmintReserves.address,
interestEarnedAccount.address,
200000 /* ltdLockDifferenceLimit */,
200000 /* ltdLoanDifferenceLimit*/,
50000 /* allowedLtdDifferenceAmount */
);

const newMonetarySupervisor = MonetarySupervisor.at(MonetarySupervisor.address);

/*************************************************************
* Deploy new Locker, setup lock products and permissions
**************************************************************/
await deployer.deploy(Locker, TokenAEur.address, MonetarySupervisor.address);
const newLocker = Locker.at(Locker.address);
console.log(" Adding test lockProducts.");
await Promise.all([
feeAccount.grantPermission(newLocker.address, "NoFeeTransferContracts"),
newMonetarySupervisor.grantPermission(newLocker.address, "LockerContracts"),

// (perTermInterest, durationInSecs, minimumLockAmount, isActive)
newLocker.addLockProduct(14472, 7776000, 1000, false), // 90 days 6% p.a.

This comment has been minimized.

Copy link
@phraktle

phraktle May 14, 2018

Collaborator

Code for parameters should be made readable (so you express 90 days / 6% in code, not the comments)

This comment has been minimized.

Copy link
@szerintedmi

szerintedmi May 14, 2018

Author Member

would using constants good enough? Ie. 90DAYS_IN_SEC?
for the perTermInterest it would be something like 6_PERCENT_PA_INTEREST_FOR_6_MONTHS_DURATION_IN_PPT
which value we calculate with a helper calculator (in google sheets).

This comment has been minimized.

Copy link
@phraktle

phraktle May 15, 2018

Collaborator

I would suggest coming up with some (unit tested) helper functions that does the conversion. Basically, your google sheet in code ;)

newLocker.addLockProduct(4019, 2592000, 1000, true), // 30 days, 5% p.a.
newLocker.addLockProduct(1506, 1209600, 1000, true), // 14 days, 4% p.a.
newLocker.addLockProduct(568, 604800, 1000, true), // 7 days, 3% p.a.

newLocker.addLockProduct(3, 3600, 2000, true), // 60 minutes for testing, ~2.66% p.a.
newLocker.addLockProduct(1, 60, 3000, true) // 1 minute for testing, ~69.15% p.a.
]);

/*************************************************************
* Deploy new LoanManager, setup loan products and permissions
**************************************************************/
await deployer.deploy(LoanManager, newTokenAEur.address, newMonetarySupervisor.address, ratesAddress);
const newLoanManager = LoanManager.at(LoanManager.address);
console.log(" Adding test loanProducts.");
await Promise.all([
feeAccount.grantPermission(newLoanManager.address, "NoFeeTransferContracts"),
newMonetarySupervisor.grantPermission(newLoanManager.address, "LoanManagerContracts"),

// term (in sec), discountRate, loanCoverageRatio, minDisbursedAmount (w/ 4 decimals), defaultingFeePt, isActive
newLoanManager.addLoanProduct(7776000, 971661, 600000, 1000, 50000, false), // 90d, 12%. p.a.

This comment has been minimized.

Copy link
@phraktle

phraktle May 14, 2018

Collaborator

Same here, make the code readable.

newLoanManager.addLoanProduct(2592000, 990641, 600000, 1000, 50000, true), // 30d, 12% p.a.
newLoanManager.addLoanProduct(1209600, 996337, 600000, 1000, 50000, true), // 14d, 10% p.a.
newLoanManager.addLoanProduct(604800, 998170, 600000, 1000, 50000, true), // 7d, 10% p.a.

newLoanManager.addLoanProduct(3600, 999989, 980000, 2000, 50000, true), // due in 1hr for testing repayments ? p.a.
newLoanManager.addLoanProduct(1, 999999, 990000, 3000, 50000, true) // defaults in 1 secs for testing ? p.a.
]);

/*************************************************************
* Grant MonetaryBoard permissions to accounts on new contracts
**************************************************************/
console.log(" Granting MonetaryBoard permissions on new contracts ");
const monetaryBoardAccounts = [
accounts[0],
"0x14A9dc091053fCbA9474c5734078238ff9904364" /* Krosza */,
"0xe71E9636e31B838aF0A3c38B3f3449cdC2b7aa87" /* Phraktle */
];
const grantMonetaryBoardTxs = monetaryBoardAccounts.map(acc => [
newExchange.grantPermission(acc, "MonetaryBoard"),
newLocker.grantPermission(acc, "MonetaryBoard"),
newTokenAEur.grantPermission(acc, "MonetaryBoard"),
newLoanManager.grantPermission(acc, "MonetaryBoard"),
newMonetarySupervisor.grantPermission(acc, "MonetaryBoard")
]);
Promise.all(grantMonetaryBoardTxs);

/*************************************************************
* Switch new MonetarySupervisor to live
**************************************************************/
console.log(" granting permissions for new MS");
await Promise.all([

This comment has been minimized.

Copy link
@phraktle

phraktle May 14, 2018

Collaborator

We should move away from free-text permissioning, since it’s very error prone (you wouldn’t know about a typo, or if the contract doesn’t even support that role)

This comment has been minimized.

Copy link
@szerintedmi

szerintedmi May 14, 2018

Author Member

That's a relatively bigger refactor, created trello card:
https://trello.com/c/SmFVaBfb/127-get-rid-of-string-based-permissions

This comment has been minimized.

Copy link
@phraktle

phraktle May 15, 2018

Collaborator

A useful step in this direction would be to use something like an enum instead of a string. The grantPermissions function could check if you are referring to a permission recognized by that contract and client code could use these constants rather than free-text.

This comment has been minimized.

Copy link
@szerintedmi

szerintedmi May 16, 2018

Author Member

I moved this suggestion (and the conversation) to the trello card

interestEarnedAccount.grantPermission(newMonetarySupervisor.address, "MonetarySupervisorContract"),
newTokenAEur.grantPermission(newMonetarySupervisor.address, "MonetarySupervisorContract"),
augmintReserves.grantPermission(newMonetarySupervisor.address, "MonetarySupervisorContract"),
feeAccount.grantPermission(newMonetarySupervisor.address, "NoFeeTransferContracts"),

newMonetarySupervisor.grantPermission(newLocker.address, "LockerContracts"),
newMonetarySupervisor.grantPermission(newLoanManager.address, "LoanManagerContracts"),
newMonetarySupervisor.grantPermission(oldLocker1.address, "LockerContracts"),
newMonetarySupervisor.grantPermission(oldLoanManager1.address, "LoanManagerContracts"),

newMonetarySupervisor.setAcceptedLegacyAugmintToken(oldToken1.address, true),
newMonetarySupervisor.setAcceptedLegacyAugmintToken(oldToken2.address, true),
newMonetarySupervisor.setAcceptedLegacyAugmintToken(oldToken3.address, true),

// to allow token conversion w/o fee
// NB: NoFeeTransferContracts was set on the token contract in legacy token version.
// For newer versions this permission needs to be set on feeAccount
oldToken1.grantPermission(newMonetarySupervisor.address, "NoFeeTransferContracts"),
oldToken2.grantPermission(newMonetarySupervisor.address, "NoFeeTransferContracts"),
feeAccount.grantPermission(oldToken3.address, "NoFeeTransferContracts")
]);

console.log(" switching new MS to live");
await Promise.all([
oldLocker1.setMonetarySupervisor(newMonetarySupervisor.address),
oldLoanManager1.setSystemContracts(ratesAddress, newMonetarySupervisor.address)
]);

// 3. migrate totals from previous MS (using MS.adjustKPIs)
const [oldTotalLoan, oldTotalLock] = await Promise.all([
oldMonetarySupervisor.totalLoanAmount(),
oldMonetarySupervisor.totalLockedAmount()
]);
console.log(
"Migrating KPIs to new MonetarySupervisor contract. totalLoanAmount:",
oldTotalLoan.toString(),
"totalLockedAmount",
oldTotalLock.toString()
);
await newMonetarySupervisor.adjustKPIs(oldTotalLoan, oldTotalLock);

console.log("Revoking permission from old MS");
await Promise.all([
feeAccount.revokePermission(oldMonetarySupervisor.address, "NoFeeTransferContracts"),
interestEarnedAccount.revokePermission(oldMonetarySupervisor.address, "MonetarySupervisorContract"),
oldToken3.revokePermission(oldMonetarySupervisor.address, "MonetarySupervisorContract"),
augmintReserves.revokePermission(oldMonetarySupervisor.address, "MonetarySupervisorContract"),

oldMonetarySupervisor.revokePermission(oldLocker1.address, "LockerContracts"),
oldMonetarySupervisor.revokePermission(oldLoanManager1.address, "LoanManagerContracts")
]);

console.log(" Done with all migration steps. Updating truffle Migrations step manually");
await Migrations.at("0xb96f7e79a6b3faf4162e274ff764ca9de598b0c5").setCompleted(17);
});
};

0 comments on commit 3620d07

Please sign in to comment.