-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdeploy_upgradeable.ts
76 lines (64 loc) · 2.31 KB
/
deploy_upgradeable.ts
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
import { ethers, ignition, upgrades } from "hardhat";
import erc20Module from "../ignition/modules/erc20";
import { getLinkedContractFactory, deploy } from "./lib/common";
export async function deployFungible(tokenName: string) {
const { erc20 } = await ignition.deploy(erc20Module);
const verifiersDeployer = require(`./tokens/${tokenName}`);
const { deployer, args, libraries } =
await verifiersDeployer.deployDependencies();
let zetoFactory;
const opts = {
kind: "uups",
initializer: "initialize",
unsafeAllow: ["delegatecall"],
};
if (libraries) {
zetoFactory = await getLinkedContractFactory(tokenName, libraries);
opts.unsafeAllow.push("external-library-linking");
} else {
zetoFactory = await ethers.getContractFactory(tokenName);
}
const proxy = await upgrades.deployProxy(zetoFactory, args, opts as any);
await proxy.waitForDeployment();
const zetoAddress = await proxy.getAddress();
const zeto: any = await ethers.getContractAt(tokenName, zetoAddress);
const tx3 = await zeto.connect(deployer).setERC20(erc20.target);
await tx3.wait();
console.log(`ZetoToken deployed: ${zeto.target}`);
console.log(`ERC20 deployed: ${erc20.target}`);
return { deployer, zeto, erc20 };
}
export async function deployNonFungible(tokenName: string) {
const verifiersDeployer = require(`./tokens/${tokenName}`);
const { deployer, args, libraries } =
await verifiersDeployer.deployDependencies();
let zetoFactory;
const opts = {
kind: "uups",
initializer: "initialize",
unsafeAllow: ["delegatecall"],
};
if (libraries) {
zetoFactory = await getLinkedContractFactory(tokenName, libraries);
opts.unsafeAllow.push("external-library-linking");
} else {
zetoFactory = await ethers.getContractFactory(tokenName);
}
const proxy = await upgrades.deployProxy(zetoFactory, args, opts as any);
await proxy.waitForDeployment();
const zetoAddress = await proxy.getAddress();
const zeto: any = await ethers.getContractAt(tokenName, zetoAddress);
console.log(`ZetoToken deployed: ${zeto.target}`);
return { deployer, zeto };
}
deploy(deployFungible, deployNonFungible)
.then(() => {
if (process.env.TEST_DEPLOY_SCRIPTS == "true") {
return;
}
process.exit(0);
})
.catch((error) => {
console.error(error);
process.exit(1);
});