-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2_5_deploy_polygon.js
121 lines (104 loc) · 4.45 KB
/
v2_5_deploy_polygon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// deploy: npx hardhat deploy --network mumbai --tags v2_5_deploy_polygon
// verify: npx hardhat etherscan-verify --network mumbai
// script is built for hardhat-deploy plugin:
// A Hardhat Plugin For Replicable Deployments And Easy Testing
// https://www.npmjs.com/package/hardhat-deploy
// we use assert to fail fast in case of any errors
const assert = require("assert");
// BN utils
const {
toBN,
print_amt,
} = require("../scripts/include/bn_utils");
// deployment utils (contract state printers)
const {
print_erc20_acl_details,
print_nft_acl_details,
print_acl_details,
} = require("../scripts/deployment_utils");
// to be picked up and executed by hardhat-deploy plugin
module.exports = async function({deployments, getChainId, getNamedAccounts, getUnnamedAccounts}) {
// print some useful info on the account we're using for the deployment
const chainId = await getChainId();
const [A0] = await web3.eth.getAccounts();
let nonce = await web3.eth.getTransactionCount(A0);
let balance = await web3.eth.getBalance(A0);
// print initial debug information
console.log("network %o %o", chainId, network.name);
console.log("service account %o, nonce: %o, balance: %o ETH", A0, nonce, print_amt(balance));
// ensure we're not deploying into the wrong place
assert(
network.name === "hardhat"
|| network.name === "localhost"
|| network.name === "polygon"
|| network.name === "polygon2"
|| network.name === "mumbai",
"unsupported network: please make sure you're deploying into Polygon"
);
// ERC20
{
// deploy if required
await deployments.deploy("PolygonAliERC20v2", {
// address (or private key) that will perform the transaction.
// you can use `getNamedAccounts` to retrieve the address you want by name.
from: A0,
contract: "PolygonAliERC20v2",
// the list of argument for the constructor (or the upgrade function in case of proxy)
// args: [],
// if set it to true, will not attempt to deploy even if the contract deployed under the same name is different
skipIfAlreadyDeployed: true,
// if true, it will log the result of the deployment (tx hash, address and gas used)
log: true,
});
// get deployment details
const deployment = await deployments.get("PolygonAliERC20v2");
// print deployment details
await print_erc20_acl_details(A0, deployment.abi, deployment.address);
}
// ERC721
{
// deploy if required
await deployments.deploy("PolygonCharacter", {
// address (or private key) that will perform the transaction.
// you can use `getNamedAccounts` to retrieve the address you want by name.
from: A0,
contract: "WhitelabelNFT",
// the list of argument for the constructor (or the upgrade function in case of proxy)
args: ["mycharacter.ai", "MYAI"],
// if set it to true, will not attempt to deploy even if the contract deployed under the same name is different
skipIfAlreadyDeployed: true,
// if true, it will log the result of the deployment (tx hash, address and gas used)
log: true,
});
// get deployment details
const deployment = await deployments.get("PolygonCharacter");
// print deployment details
await print_nft_acl_details(A0, deployment.abi, deployment.address);
}
// NFT Factory
{
// deploy if required
await deployments.deploy("CharacterFactory", {
// address (or private key) that will perform the transaction.
// you can use `getNamedAccounts` to retrieve the address you want by name.
from: A0,
contract: "NFTFactory",
// the list of argument for the constructor (or the upgrade function in case of proxy)
// args: [],
// if set it to true, will not attempt to deploy even if the contract deployed under the same name is different
skipIfAlreadyDeployed: true,
// if true, it will log the result of the deployment (tx hash, address and gas used)
log: true,
});
// get deployment details
const deployment = await deployments.get("CharacterFactory");
// print deployment details
await print_acl_details(A0, deployment.abi, deployment.address);
}
};
// Tags represent what the deployment script acts on. In general, it will be a single string value,
// the name of the contract it deploys or modifies.
// Then if another deploy script has such tag as a dependency, then when the latter deploy script has a specific tag
// and that tag is requested, the dependency will be executed first.
// https://www.npmjs.com/package/hardhat-deploy#deploy-scripts-tags-and-dependencies
module.exports.tags = ["v2_5_deploy_polygon", "deploy_polygon", "v2_5"];