Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for simple exit contract #362

Merged
merged 10 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add exit contract fixtures
  • Loading branch information
David Scharf committed Mar 29, 2021
commit 0be26f9d25a50d18ec42a94f509a1c83fa0898bc
4 changes: 1 addition & 3 deletions migrations/106_deploy_fixture_commitments.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ module.exports = function deployContracts(deployer, network, accounts) {
for (const name of Object.keys(etoFixtures)) {
const etoVars = etoFixtures[name];
const etoTerms = prepareEtoTerms(name, etoVars.terms);
console.log(
`Deploying eto fixture ${name} state ${etoVars.state} issuer ${etoVars.issuer}`,
);
console.log(`Deploying eto fixture ${name} state ${etoVars.state} issuer ${etoVars.issuer}`);

const nominee = findNomineeForEto(name, fas);

Expand Down
82 changes: 82 additions & 0 deletions migrations/107_add_exit_contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require("babel-register");
const { etoFixtures } = require("./fixtures/etos");
const { Q18 } = require("../test/helpers/constants");
const { getConfig, getDeployerAccount } = require("./config");
const { loadEtoFixtures, getEtoFixtureByName } = require("./helpers");
const knownInterfaces = require("../test/helpers/knownInterfaces").knownInterfaces;
const toChecksumAddress = require("web3-utils").toChecksumAddress;
const stringify = require("../test/helpers/utils").stringify;
const { join } = require("path");
const fs = require("fs");

module.exports = function deployContracts(deployer, network, accounts) {
const CONFIG = getConfig(web3, network, accounts);

if (CONFIG.isLiveDeployment) return;

deployer.then(async () => {
const DEPLOYER = getDeployerAccount(network, accounts);
const Universe = artifacts.require(CONFIG.artifacts.UNIVERSE);
const universe = await Universe.deployed();
const ExitController = artifacts.require(CONFIG.artifacts.EXIT_CONTROLLER);
const savedEtoFixtures = loadEtoFixtures();
const EuroToken = artifacts.require(CONFIG.artifacts.EURO_TOKEN);
const EuroTokenController = artifacts.require(CONFIG.artifacts.EURO_TOKEN_CONTROLLER);
const euroToken = await EuroToken.at(await universe.euroToken());
const euroTokenController = await EuroTokenController.at(await euroToken.tokenController());

const exitControllers = {};

for (const name of Object.keys(etoFixtures)) {
const etoVars = etoFixtures[name];
if (etoVars.exit) {
console.log(`Deploying ExitContract for eto ${name} for ${etoVars.exit} Euros`);

// deploy exit controller for eto fixture and register with universe
const etoFixture = getEtoFixtureByName(savedEtoFixtures, name);
const nominee = etoFixture.nominee;
const exitController = await ExitController.new(universe.address, etoFixture.equityToken);
await universe.setCollectionsInterfaces(
[knownInterfaces.exitController],
[exitController.address],
[true],
{ from: DEPLOYER },
);

console.log(`Start exit with nominee transfer`);
// set eur-t transfer whitelist for exit controller
await euroTokenController.setAllowedTransferTo(exitController.address, true, {
from: DEPLOYER,
});
await euroTokenController.setAllowedTransferFrom(exitController.address, true, {
from: DEPLOYER,
});

// start exit from nominee, nominee will need enough funds in eur-t
const exitAmount = Q18.mul(etoVars.exit);
await euroToken.transfer["address,uint256,bytes"](exitController.address, exitAmount, "", {
from: nominee,
});

// verify that payout has started
const state = await exitController.state();
if (state !== 1) {
throw new Error("ExitController in incorrect state after deployment");
}

console.log(`Validate exit controller state is ${state}`);

// save exit controller
exitControllers[name] = stringify({
address: toChecksumAddress(exitController.address),
amount_eurt: exitAmount,
});
}
}

const exitControllerPath = join(__dirname, "../build/exit_controller_fixtures.json");
fs.writeFile(exitControllerPath, JSON.stringify(exitControllers, null, 2), err => {
if (err) throw new Error(err);
});
});
};
3 changes: 2 additions & 1 deletion migrations/fixtures/accounts.json
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,8 @@
"address": "0x5A72Dce8025165C416F77739c157403E978738dE",
"type": "nominee",
"balances": {
"initialEth": 100
"initialEth": 100,
"euroToken": 20000000
},
"identityClaims": {
"isVerified": true,
Expand Down
3 changes: 1 addition & 2 deletions migrations/fixtures/etos.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ export const etoFixtures = {
state: CommitmentState.Payout,
issuer: fas.ISSUER_EXIT,
terms: retailEtoDeVmaTerms,
hasExitContract: true
exit: "11000000", // 11 mio
},

ETOInRefundState: {
state: CommitmentState.Refund,
issuer: fas.ISSUER_REFUND,
terms: defEtoTerms,
},

};
2 changes: 2 additions & 0 deletions test/helpers/artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const artifacts = {
ETO_TERMS_CONSTRAINTS: "ETOTermsConstraints",
VOTING_CENTER: "VotingCenter",
VOTING_CENTER_CONTROLLER: "VotingController",
EXIT_CONTROLLER: "ExitController",

// not implemented
// PLATFORM_PORTFOLIO: "IPlatformPortfolio"
};
1 change: 1 addition & 0 deletions test/helpers/interfaceArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const interfaceToArtifacts = {
[keyToKey.equityTokenControllerInterface]: [artifacts.EQUITY_TOKEN_CONTROLLER, ""],
[keyToKey.termsInterface]: [artifacts.STANDARD_ETO_TERMS, ""],
[keyToKey.etoTermsConstraints]: [artifacts.ETO_TERMS_CONSTRAINTS, ""],
[keyToKey.exitController]: [artifacts.EXIT_CONTROLLER, ""],
};

// verify all known interfaces are mapped
Expand Down
1 change: 1 addition & 0 deletions test/helpers/knownInterfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export const knownInterfaces = {
paymentTokenInterface: sha3("PaymentToken").slice(0, 10),
etoTermsConstraints: sha3("ETOTermsConstraints").slice(0, 10),
votingCenter: sha3("IVotingCenter").slice(0, 10),
exitController: sha3("ExitController").slice(0, 10),
};