forked from fei-protocol/fei-protocol-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructProposal.ts
More file actions
56 lines (47 loc) · 1.95 KB
/
Copy pathconstructProposal.ts
File metadata and controls
56 lines (47 loc) · 1.95 KB
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
import { proposals } from 'hardhat';
import { MainnetContracts, NamedAddresses, ProposalDescription } from '@custom-types/types';
import format from 'string-template';
import { AlphaProposal } from '@idle-finance/hardhat-proposals-plugin/dist/src/proposals/compound-alpha';
/**
* Constucts a hardhat proposal object
* https://github.com/Idle-Finance/hardhat-proposals-plugin/blob/main/src/proposals/proposal.ts
*
*/
export default async function constructProposal(
proposalInfo: ProposalDescription,
contracts: MainnetContracts,
contractAddresses: NamedAddresses,
logging = false
): Promise<AlphaProposal> {
logging && console.log(`Constructing proposal...`);
const proposalDescription = proposalInfo.description;
const proposalBuilder = proposals.builders.alpha();
proposalBuilder.maxActions = 40;
for (let i = 0; i < proposalInfo.commands.length; i += 1) {
const command = proposalInfo.commands[i];
const ethersContract = contracts[command.target];
const args = replaceArgs(command.arguments, contractAddresses);
proposalBuilder.addContractAction(ethersContract, command.method, args, command.values);
logging && console.log(`Adding proposal step: ${command.description}`);
}
proposalBuilder.setDescription(`${proposalInfo.title}\n${proposalDescription.toString()}`); // Set proposal description
const proposal = proposalBuilder.build();
logging && console.log(await proposal.printProposalInfo());
return proposal;
}
// Recursively interpolate strings in the argument array
const replaceArgs = (args: any[], contractNames: NamedAddresses) => {
const result = [];
for (let i = 0; i < args.length; i++) {
const element = args[i];
if (typeof element === typeof '') {
const formatted = format(element, contractNames);
result.push(formatted);
} else if (typeof element === typeof []) {
result.push(replaceArgs(element, contractNames));
} else {
result.push(element);
}
}
return result;
};