This repository has been archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
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 #51 from atpar/APm-45-rewrite-deploy
APm-45-rewrite-deploy
- Loading branch information
Showing
101 changed files
with
52,600 additions
and
4,088 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,5 @@ yarn test | |
|
||
### Deploy to local ganache chain | ||
```sh | ||
yarn migrate:ap-chain | ||
yarn setup-ap-chain | ||
``` |
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
13 changes: 13 additions & 0 deletions
13
packages/ap-contracts/deploy/0-include-tags-to-deploy-ap-chain.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,13 @@ | ||
// Deploy contracts on the ap-chain | ||
// NOTE: (unlike "migrate") it updates neither deployments nor artifacts | ||
module.exports = async () => await Promise.resolve(); | ||
module.exports.tags = ["deploy-ap-chain"]; | ||
module.exports.dependencies = [ | ||
"_env", | ||
"_package", | ||
"_deployment", | ||
"_init", | ||
]; | ||
|
||
// run on the ap-chain only | ||
module.exports.skip = ({ usrNs: { chainId }}) => Promise.resolve(chainId !== '1994'); |
12 changes: 12 additions & 0 deletions
12
packages/ap-contracts/deploy/0-include-tags-to-generate-artifacts.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,12 @@ | ||
// Generate artifacts | ||
module.exports = async () => await Promise.resolve(); | ||
module.exports.tags = ["artifacts"]; | ||
module.exports.dependencies = [ | ||
"_env", | ||
"_package", | ||
"_deployment", // deployments needed just to get metadata | ||
"_artifacts", // generate '../artifacts/*.min.json' files | ||
]; | ||
|
||
// run on the buidlerEVM network only | ||
module.exports.skip = ({ usrNs: { chainId }}) => Promise.resolve(`${chainId}` !== '31337' ); |
7 changes: 7 additions & 0 deletions
7
packages/ap-contracts/deploy/0-include-tags-to-migrate-with-rejection-termination.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,7 @@ | ||
// Make node.js terminate on unhandled rejections, and run "migrate" | ||
module.exports = async () => await Promise.resolve(); | ||
module.exports.tags = ["migrate-terminate"]; | ||
module.exports.dependencies = [ | ||
"_terminate-on-rejections", | ||
"migrate" | ||
]; |
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,12 @@ | ||
// Deploy contracts and update deployments.js | ||
module.exports = async () => await Promise.resolve(); | ||
module.exports.tags = ["migrate"]; | ||
module.exports.dependencies = [ | ||
"_env", // extend buidler runtime environment | ||
"_package", // define contracts to deploy | ||
"_balance", // assert deployer balance | ||
"_deployment", // deploy contracts | ||
"_init", // init contracts | ||
"_export", // update '../deployments.js' | ||
"_verification", // do contract verification | ||
]; |
12 changes: 12 additions & 0 deletions
12
packages/ap-contracts/deploy/0-include-tags-to-setup-tests.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,12 @@ | ||
// declares tags (dependencies) only | ||
module.exports = async () => await Promise.resolve(); | ||
module.exports.tags = ["u-tests", "e2e-tests"] | ||
module.exports.dependencies = [ | ||
"_env", | ||
"_env-tests", | ||
"_package", | ||
"_deployment", | ||
"_init", | ||
"_init-tests", | ||
"_instances-tests", | ||
]; |
32 changes: 32 additions & 0 deletions
32
packages/ap-contracts/deploy/1-extend-buidler-env-for-tests.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,32 @@ | ||
module.exports = extendBuidlerEnvForTests; | ||
module.exports.tags = ["_env-tests"]; | ||
module.exports.dependencies = ["_env"]; | ||
|
||
/** | ||
* @typedef {import('./1-extend-buidler-env').ExtendedBRE} | ||
* @typedef Instances {{name: string, instance: any}} - web3 Contract objects, name: contract name + 'Instance' | ||
* @typedef {ExtendedBRE} ExtendedTestBRE | ||
* @property {Instances} instances | ||
*/ | ||
|
||
/** @param {ExtendedBRE} buidlerRuntime */ | ||
async function extendBuidlerEnvForTests(buidlerRuntime) { | ||
|
||
const { deployments: { log }, usrNs, web3 } = buidlerRuntime; | ||
const { accounts, roles } = usrNs; | ||
|
||
if (!usrNs.instances) usrNs.instances = {}; | ||
|
||
roles.defaultActor = checkAddress(accounts[2]); | ||
log(`roles: ${JSON.stringify(roles, null, 2)}`); | ||
|
||
// shall be async | ||
return Promise.resolve(); | ||
|
||
function checkAddress(address) { | ||
if (!web3.utils.isAddress(address)) { | ||
throw new Error(`invalid address ${address}`); | ||
} | ||
return address; | ||
} | ||
} |
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,57 @@ | ||
module.exports = extendBuidlerEnv; | ||
module.exports.tags = ["_env"]; | ||
|
||
/** | ||
* @typedef {Object} BuidlerRuntimeEnvironment (https://github.com/wighawag/buidler-deploy#environment-extensions) | ||
* | ||
* @typedef {{name: string: address: string}} Roles | ||
* @typedef UserNamespace | ||
* @property {String} chainId | ||
* @property {String[]} accounts | ||
* @property {Roles} roles | ||
* @property {import('./2-define-package').Package} package | ||
* @property {{name: string, helper:any}} helpers - misc helper functions | ||
* | ||
* @typedef {BuidlerRuntimeEnvironment} ExtendedBRE - extended Builder Runtime Environment | ||
* @property {UserNamespace} usrNs - extension | ||
*/ | ||
|
||
/** @param buidlerRuntime {ExtendedBRE} */ | ||
async function extendBuidlerEnv(buidlerRuntime) { | ||
if (typeof buidlerRuntime.usrNs !== 'undefined') throw new Error("unexpected Buidler Runtime Environment"); | ||
|
||
const { deployments: { log }, getNamedAccounts, getChainId, web3 } = buidlerRuntime; | ||
|
||
const { admin, deployer } = await getNamedAccounts(); | ||
const id = `${await getChainId()}`; | ||
|
||
// ganache hardcoded to return 1337 on 'eth_chainId' RPC request that buidler uses | ||
const chainId = ( id === '1337' ) ? `${await web3.eth.net.getId()}` : id; | ||
|
||
const accounts = await web3.eth.getAccounts(); | ||
const roles = { | ||
deployer: deployer || accounts[0], | ||
admin: admin || accounts[1] || accounts[0], | ||
}; | ||
Object.keys(roles).forEach( | ||
(key) => { | ||
if (!web3.utils.isAddress(roles[key])) { | ||
throw new Error(`invalid address for role: ${key}`); | ||
} | ||
} | ||
); | ||
|
||
if (!web3.eth.Contract.defaultAccount) { | ||
web3.eth.Contract.defaultAccount = deployer; | ||
} | ||
|
||
buidlerRuntime.usrNs = { | ||
chainId, | ||
accounts, | ||
roles, | ||
package: {}, | ||
helpers: {}, | ||
}; | ||
|
||
log(`Buidler Runtime Environment extended, chainId: ${chainId}`); | ||
} |
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,140 @@ | ||
module.exports = definePackage; | ||
module.exports.tags = ["_package"]; | ||
module.exports.dependencies = ["_env"]; | ||
|
||
/** | ||
* @typedef {Object} DeployOptions - https://github.com/wighawag/buidler-deploy#deploy-function | ||
* @typedef {import('./1-extend-buidler-env').ExtendedBRE} | ||
* | ||
* @typedef {Object} ContractsListItem | ||
* @property {string} name - contract name | ||
* @property {DeployOptions} [options] | ||
* @property {function (ExtendedBRE): DeployOptions} [getOptions] - getter for options | ||
* @property {boolean} [exportable] - `true` to export into `deployments.json` and `artifacts/` (default - `true`) | ||
* @property {boolean} [deployable] - if `false`, neither deploy nor export to `deployments.json` (default - `true`) | ||
* | ||
* @typedef {Object} Package | ||
* @property {ContractsListItem[]} contracts | ||
* @property {DeployOptions} defaultDeployOptions | ||
*/ | ||
|
||
/** @param {ExtendedBRE} buidlerRuntime */ | ||
async function definePackage(buidlerRuntime) { | ||
|
||
const { deployments: { log }, usrNs } = buidlerRuntime; | ||
if ( typeof usrNs !== 'object' || typeof usrNs.package !== 'object' ) { | ||
throw new Error("unexpected Buidler Runtime Environment"); | ||
} | ||
|
||
usrNs.package.contracts = [ | ||
|
||
// ACTUS-Solidity | ||
{ name: "ANNEngine" }, | ||
{ name: "CECEngine" }, | ||
{ name: "CEGEngine" }, | ||
{ name: "CERTFEngine" }, | ||
{ name: "PAMEngine" }, | ||
|
||
// Asset Registry | ||
{ name: "ANNEncoder", exportable: false }, | ||
{ name: "CECEncoder", exportable: false }, | ||
{ name: "CEGEncoder", exportable: false }, | ||
{ name: "CERTFEncoder", exportable: false }, | ||
{ name: "PAMEncoder", exportable: false }, | ||
{ | ||
name: "ANNRegistry", | ||
options: { libraries: { ANNEncoder: "{{ANNEncoder.address}}" }}, | ||
}, | ||
{ | ||
name: "CECRegistry", | ||
options: { libraries: { CECEncoder: "{{CECEncoder.address}}" }}, | ||
}, | ||
{ | ||
name: "CEGRegistry", | ||
options: { libraries: { CEGEncoder: "{{CEGEncoder.address}}" }}, | ||
}, | ||
{ | ||
name: "CERTFRegistry", | ||
options: { libraries: { CERTFEncoder: "{{CERTFEncoder.address}}" }}, | ||
}, | ||
{ | ||
name: "PAMRegistry", | ||
options: { libraries: { PAMEncoder: "{{PAMEncoder.address}}" }}, | ||
}, | ||
|
||
// Data Registry | ||
{ name: "DataRegistry" }, | ||
|
||
// Asset Actor | ||
{ | ||
name: "ANNActor", | ||
options: { args: [ "{{ANNRegistry.address}}", "{{DataRegistry.address}}" ]}, | ||
}, | ||
{ | ||
name: "CECActor", | ||
options: { args: [ "{{CECRegistry.address}}", "{{DataRegistry.address}}" ]}, | ||
}, | ||
{ | ||
name: "CEGActor", | ||
options: { args: [ "{{CEGRegistry.address}}", "{{DataRegistry.address}}" ]}, | ||
}, | ||
{ | ||
name: "CERTFActor", | ||
options: { args: [ "{{CERTFRegistry.address}}", "{{DataRegistry.address}}" ]}, | ||
}, | ||
{ | ||
name: "PAMActor", | ||
options: { args: [ "{{PAMRegistry.address}}", "{{DataRegistry.address}}" ]}, | ||
}, | ||
|
||
// Custodian | ||
{ | ||
name: "Custodian", | ||
options: { args: [ "{{CECActor.address}}", "{{CECRegistry.address}}" ]}, | ||
}, | ||
|
||
// FDT | ||
{ name: "ProxySafeVanillaFDT", exportable: false }, | ||
{ name: "ProxySafeSimpleRestrictedFDT", exportable: false }, | ||
{ | ||
name: "FDTFactory", | ||
options: { libraries: { | ||
VanillaFDTLogic: "{{ProxySafeVanillaFDT.address}}", | ||
SimpleRestrictedFDTLogic: "{{ProxySafeSimpleRestrictedFDT.address}}", | ||
}}, | ||
}, | ||
|
||
// ICT | ||
{ name: "ProxySafeICT", exportable: false }, | ||
{ | ||
name: "ICTFactory", | ||
exportable: false, | ||
options: { libraries: { ICTLogic: "{{ProxySafeICT.address}}" }}, | ||
}, | ||
|
||
// DvPSettlement | ||
{ name: "DvPSettlement" }, | ||
|
||
// settlement token (for templates on testnets) | ||
{ name: "SettlementToken", exportable: false }, | ||
|
||
// export artifacts only (do not deploy) | ||
{ name: "BaseActor", deployable: false }, | ||
{ name: "BaseRegistry", deployable: false }, | ||
{ name: "ERC20", deployable: false }, | ||
{ name: "ERC1404", deployable: false }, | ||
{ name: "VanillaFDT", deployable: false } | ||
|
||
]; | ||
|
||
usrNs.package.defaultDeployOptions = { | ||
from: usrNs.roles.deployer, | ||
gas: 4500000, | ||
log: true, | ||
}; | ||
|
||
log(`${usrNs.package.contracts.length} contracts defined`); | ||
|
||
// shall be async | ||
return Promise.resolve(); | ||
} |
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,22 @@ | ||
module.exports = assertDeployerBalance; | ||
module.exports.tags = ["_balance"]; | ||
module.exports.dependencies = ["_env"]; | ||
|
||
/** | ||
* @typedef {import('./1-extend-buidler-env').ExtendedBRE} | ||
* @param {ExtendedBRE} buidlerRuntime | ||
*/ | ||
async function assertDeployerBalance(buidlerRuntime) { | ||
|
||
const { deployments: { log }, usrNs: { roles: { deployer } }, web3 } = buidlerRuntime; | ||
|
||
if ( !web3.utils.isAddress(deployer) ) { | ||
throw new Error("unexpected Buidler Runtime Environment"); | ||
} | ||
const balance = parseFloat(web3.utils.fromWei(await web3.eth.getBalance(deployer), 'ether')); | ||
if( balance < 0.5 ) { | ||
log(`ATTENTION!!! low deployer balance: ${balance} ether`); | ||
} else { | ||
log(`deployer balance: ${balance} ether`); | ||
} | ||
} |
Oops, something went wrong.