Skip to content

Commit 3301b6a

Browse files
pblivin0xcgewecke
andauthored
chore(scripts): Add DelegatedManager system Avalanche deploy script [SIM-310] (#42)
* add WIP DelegatedManagerSystem avax deploy scripts * Fix test command and git ignore development outputs * fix dependency addresses * update DebtIssuanceModuleV2 staging address Co-authored-by: cgewecke <[email protected]>
1 parent 0f893bf commit 3301b6a

File tree

9 files changed

+417
-30
lines changed

9 files changed

+417
-30
lines changed

avalanche/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/deployments/production/*
1313
/deployments/outputs/staging_mainnet_1
1414
/deployments/outputs/production_1
15-
/deployments/outputs/50-development.json
15+
/deployments/outputs/43114-development.json
1616
/deploy/*_fake_deployment.ts
1717
/node_modules
1818
/transpiled
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
import "module-alias/register";
2+
3+
import { HardhatRuntimeEnvironment as HRE } from "hardhat/types";
4+
import { DeployFunction } from "hardhat-deploy/types";
5+
6+
import {
7+
prepareDeployment,
8+
findDependency,
9+
getContractAddress,
10+
getCurrentStage,
11+
saveContractDeployment,
12+
stageAlreadyFinished,
13+
trackFinishedStage,
14+
writeTransactionToOutputs,
15+
getAccounts,
16+
} from "@utils/index";
17+
18+
import { Account } from "@utils/types";
19+
import { InstanceGetter } from "@utils/instanceGetter";
20+
21+
import { DEPENDENCY } from "../deployments/utils/dependencies";
22+
import { CONTRACT_NAMES } from "../deployments/constants/001_delegated_manager_system";
23+
24+
const {
25+
MULTI_SIG_OWNER,
26+
CONTROLLER,
27+
SET_TOKEN_CREATOR,
28+
DEBT_ISSUANCE_MODULE_V2,
29+
STREAMING_FEE_MODULE,
30+
TRADE_MODULE,
31+
} = DEPENDENCY;
32+
33+
let owner: Account;
34+
let instanceGetter: InstanceGetter;
35+
36+
const CURRENT_STAGE = getCurrentStage(__filename);
37+
38+
const func: DeployFunction = trackFinishedStage(CURRENT_STAGE, async function (bre: HRE) {
39+
const {
40+
deploy,
41+
deployer,
42+
rawTx,
43+
networkConstant
44+
} = await prepareDeployment(bre);
45+
46+
[owner] = await getAccounts();
47+
instanceGetter = new InstanceGetter(owner.wallet);
48+
49+
await deployManagerCore();
50+
const managerCoreAddress = await getContractAddress(CONTRACT_NAMES.MANAGER_CORE);
51+
52+
const controllerAddress = await findDependency(CONTROLLER);
53+
const setTokenCreatorAddress = await findDependency(SET_TOKEN_CREATOR);
54+
await deployDelegatedManagerFactory();
55+
const delegatedManagerFactoryAddress = await getContractAddress(CONTRACT_NAMES.DELEGATED_MANAGER_FACTORY);
56+
57+
const issuanceModuleAddress = await findDependency(DEBT_ISSUANCE_MODULE_V2);
58+
await deployIssuanceExtension();
59+
const issuanceExtensionAddress = await getContractAddress(CONTRACT_NAMES.ISSUANCE_EXTENSION);
60+
61+
const streamingFeeModuleAddress = await findDependency(STREAMING_FEE_MODULE);
62+
await deployStreamingFeeSplitExtension();
63+
const streamingFeeSplitExtensionAddress = await getContractAddress(CONTRACT_NAMES.STREAMING_FEE_SPLIT_EXTENSION);
64+
65+
const tradeModuleAddress = await findDependency(TRADE_MODULE);
66+
await deployTradeExtension();
67+
const tradeExtensionAddress = await getContractAddress(CONTRACT_NAMES.TRADE_EXTENSION);
68+
69+
await initializeManagerCore();
70+
71+
await transferManagerCoreOwnershipToMultisig();
72+
73+
//
74+
// Helper Functions
75+
//
76+
77+
async function deployManagerCore(): Promise<void> {
78+
const checkManagerCoreAddress = await getContractAddress(CONTRACT_NAMES.MANAGER_CORE);
79+
if (checkManagerCoreAddress === "") {
80+
const managerCoreDeploy = await deploy(
81+
CONTRACT_NAMES.MANAGER_CORE,
82+
{ from: deployer, log: true }
83+
);
84+
managerCoreDeploy.receipt && await saveContractDeployment({
85+
name: CONTRACT_NAMES.MANAGER_CORE,
86+
contractAddress: managerCoreDeploy.address,
87+
id: managerCoreDeploy.receipt.transactionHash,
88+
description: `Deployed ${CONTRACT_NAMES.MANAGER_CORE}`
89+
});
90+
}
91+
}
92+
93+
async function deployDelegatedManagerFactory(): Promise<void> {
94+
const checkDelegatedManagerFactoryAddress = await getContractAddress(CONTRACT_NAMES.DELEGATED_MANAGER_FACTORY);
95+
if (checkDelegatedManagerFactoryAddress === "") {
96+
const constructorArgs = [managerCoreAddress, controllerAddress, setTokenCreatorAddress];
97+
const delegatedManagerFactoryDeploy = await deploy(
98+
CONTRACT_NAMES.DELEGATED_MANAGER_FACTORY,
99+
{ from: deployer, args: constructorArgs, log: true }
100+
);
101+
delegatedManagerFactoryDeploy.receipt && await saveContractDeployment({
102+
name: CONTRACT_NAMES.DELEGATED_MANAGER_FACTORY,
103+
contractAddress: delegatedManagerFactoryDeploy.address,
104+
id: delegatedManagerFactoryDeploy.receipt.transactionHash,
105+
description: `Deployed ${CONTRACT_NAMES.DELEGATED_MANAGER_FACTORY}`,
106+
constructorArgs,
107+
});
108+
}
109+
}
110+
111+
async function deployIssuanceExtension(): Promise<void> {
112+
const checkIssuanceExtensionAddress = await getContractAddress(CONTRACT_NAMES.ISSUANCE_EXTENSION);
113+
if (checkIssuanceExtensionAddress === "") {
114+
const constructorArgs = [managerCoreAddress, issuanceModuleAddress];
115+
const issuanceExtensionDeploy = await deploy(
116+
CONTRACT_NAMES.ISSUANCE_EXTENSION,
117+
{ from: deployer, args: constructorArgs, log: true }
118+
);
119+
issuanceExtensionDeploy.receipt && await saveContractDeployment({
120+
name: CONTRACT_NAMES.ISSUANCE_EXTENSION,
121+
contractAddress: issuanceExtensionDeploy.address,
122+
id: issuanceExtensionDeploy.receipt.transactionHash,
123+
description: `Deployed ${CONTRACT_NAMES.ISSUANCE_EXTENSION}`,
124+
constructorArgs,
125+
});
126+
}
127+
}
128+
129+
async function deployStreamingFeeSplitExtension(): Promise<void> {
130+
const checkStreamingFeeSplitExtensionAddress = await getContractAddress(CONTRACT_NAMES.STREAMING_FEE_SPLIT_EXTENSION);
131+
if (checkStreamingFeeSplitExtensionAddress === "") {
132+
const constructorArgs = [managerCoreAddress, streamingFeeModuleAddress];
133+
const streamingFeeSplitExtensionDeploy = await deploy(
134+
CONTRACT_NAMES.STREAMING_FEE_SPLIT_EXTENSION,
135+
{ from: deployer, args: constructorArgs, log: true }
136+
);
137+
streamingFeeSplitExtensionDeploy.receipt && await saveContractDeployment({
138+
name: CONTRACT_NAMES.STREAMING_FEE_SPLIT_EXTENSION,
139+
contractAddress: streamingFeeSplitExtensionDeploy.address,
140+
id: streamingFeeSplitExtensionDeploy.receipt.transactionHash,
141+
description: `Deployed ${CONTRACT_NAMES.STREAMING_FEE_SPLIT_EXTENSION}`,
142+
constructorArgs,
143+
});
144+
}
145+
}
146+
147+
async function deployTradeExtension(): Promise<void> {
148+
const checkTradeExtensionAddress = await getContractAddress(CONTRACT_NAMES.TRADE_EXTENSION);
149+
if (checkTradeExtensionAddress === "") {
150+
const constructorArgs = [managerCoreAddress, tradeModuleAddress];
151+
const tradeExtensionDeploy = await deploy(
152+
CONTRACT_NAMES.TRADE_EXTENSION,
153+
{ from: deployer, args: constructorArgs, log: true }
154+
);
155+
tradeExtensionDeploy.receipt && await saveContractDeployment({
156+
name: CONTRACT_NAMES.TRADE_EXTENSION,
157+
contractAddress: tradeExtensionDeploy.address,
158+
id: tradeExtensionDeploy.receipt.transactionHash,
159+
description: `Deployed ${CONTRACT_NAMES.TRADE_EXTENSION}`,
160+
constructorArgs,
161+
});
162+
}
163+
}
164+
165+
async function initializeManagerCore(): Promise<void> {
166+
const managerCoreInstance = await instanceGetter.getManagerCore(managerCoreAddress);
167+
if (!await managerCoreInstance.isInitialized()) {
168+
const initializeData = managerCoreInstance.interface.encodeFunctionData(
169+
"initialize",
170+
[[issuanceExtensionAddress, streamingFeeSplitExtensionAddress, tradeExtensionAddress], [delegatedManagerFactoryAddress]]
171+
);
172+
const description = "Initialized ManagerCore with DelegatedManagerFactory, IssuanceExtension, StreamingFeeSplitExtension, and TradeExtension";
173+
174+
const initializeTransaction: any = await rawTx({
175+
from: deployer,
176+
to: managerCoreAddress,
177+
data: initializeData,
178+
log: true,
179+
});
180+
await writeTransactionToOutputs(initializeTransaction.transactionHash, description);
181+
}
182+
}
183+
184+
async function transferManagerCoreOwnershipToMultisig(): Promise<void> {
185+
if (networkConstant === "production") {
186+
const multisig = await findDependency(MULTI_SIG_OWNER);
187+
const managerCoreInstance = await instanceGetter.getManagerCore(managerCoreAddress);
188+
189+
const managerCoreOwner = await managerCoreInstance.owner();
190+
if (multisig !== "" && managerCoreOwner === deployer) {
191+
const transferOwnershipData = managerCoreInstance.interface.encodeFunctionData(
192+
"transferOwnership",
193+
[multisig]
194+
);
195+
196+
const transferOwnershipTransaction: any = await rawTx({
197+
from: deployer,
198+
to: managerCoreAddress,
199+
data: transferOwnershipData,
200+
log: true,
201+
});
202+
203+
await writeTransactionToOutputs(
204+
transferOwnershipTransaction.transactionHash,
205+
"Transfer ManagerCore ownership to Multisig"
206+
);
207+
}
208+
}
209+
}
210+
});
211+
212+
func.skip = stageAlreadyFinished(CURRENT_STAGE);
213+
214+
export default func;

avalanche/deploy/001_example.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const CONTRACT_NAMES = {
2+
MANAGER_CORE: "ManagerCore",
3+
DELEGATED_MANAGER_FACTORY:"DelegatedManagerFactory",
4+
ISSUANCE_EXTENSION:"IssuanceExtension",
5+
STREAMING_FEE_SPLIT_EXTENSION:"StreamingFeeSplitExtension",
6+
TRADE_EXTENSION:"TradeExtension",
7+
};

avalanche/deployments/constants/001_example.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

avalanche/deployments/utils/dependencies.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ export default {
8787
43114: "",
8888
},
8989

90+
// Set Protocol System
91+
CONTROLLER: {
92+
43114: {
93+
staging: "0x14099863F0B6490759f9D8bC5653CF52b7eF38eb",
94+
production: ""
95+
},
96+
},
97+
SET_TOKEN_CREATOR: {
98+
43114: {
99+
staging: "0xE99447aBbD5A7730b26D2D16fCcB2086319e4bC3",
100+
production: ""
101+
},
102+
},
103+
DEBT_ISSUANCE_MODULE_V2: {
104+
43114: {
105+
staging: "0x1eAF9C71AaDD5339D088eF36bF383f909a0c9780",
106+
production: ""
107+
},
108+
},
109+
STREAMING_FEE_MODULE: {
110+
43114: {
111+
staging: "0x4F70287526ea9Ba7e799D616ea86635CdAf0de4F",
112+
production: ""
113+
},
114+
},
115+
TRADE_MODULE: {
116+
43114: {
117+
staging: "0x44279c2cbFaa14D354144895B0c7771c597d6944",
118+
production: ""
119+
},
120+
},
121+
90122
HUMAN_FRIENDLY_NAMES: {
91123
50: "test-rpc",
92124
43114: "avalanche-mainnet",
@@ -121,8 +153,11 @@ export const DEPENDENCY = {
121153
MULTI_SIG_OWNER: "MULTI_SIG_OWNER",
122154

123155
// System Contracts
124-
CONTROLLER: "Controller",
125-
BASIC_ISSUANCE_MODULE: "BasicIssuanceModule",
126-
NAV_ISSUANCE_MODULE: "NavIssuanceModule",
127-
SET_TOKEN_CREATOR: "SetTokenCreator",
156+
CONTROLLER: "CONTROLLER",
157+
BASIC_ISSUANCE_MODULE: "BASIC_ISSUANCE_MODULE",
158+
NAV_ISSUANCE_MODULE: "NAV_ISSUANCE_MODULE",
159+
SET_TOKEN_CREATOR: "SET_TOKEN_CREATOR",
160+
DEBT_ISSUANCE_MODULE_V2:"DEBT_ISSUANCE_MODULE_V2",
161+
STREAMING_FEE_MODULE: "STREAMING_FEE_MODULE",
162+
TRADE_MODULE: "TRADE_MODULE",
128163
};

avalanche/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"hardhat": "../node_modules/.bin/hardhat",
2121
"lint": "cd .. && yarn lint",
2222
"lint:nofix": "cd .. && yarn lint:nofix",
23-
"test": ". ./env/local.sh; yarn hardhat test",
23+
"test": ". ./env/local.sh; yarn clean-dev-deployment && yarn hardhat test",
2424
"transpile": "../node_modules/.bin/tsc",
2525
"tx": ". ./env/production.sh; yarn hardhat set:utils:tx",
2626
"tx-dev": "TESTING_PRODUCTION=true yarn hardhat set:utils:tx",

0 commit comments

Comments
 (0)