Skip to content

Commit

Permalink
feat: allow to select voting network via generator (bgd-labs#335)
Browse files Browse the repository at this point in the history
* feat: allow to select voting network via generator

* Update generator/common.ts

Co-authored-by: Lukas <[email protected]>

* fix: default votingPortal polygon and fix test

---------

Co-authored-by: Lukas <[email protected]>
  • Loading branch information
brotherlymite and sakulstra authored May 13, 2024
1 parent 4c1a1b2 commit 410c8c5
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
20 changes: 19 additions & 1 deletion generator/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import {Command, Option} from 'commander';
import {CHAIN_TO_CHAIN_ID, getDate, getPoolChain, isV2Pool, pascalCase} from './common';
import {input, checkbox} from '@inquirer/prompts';
import {input, checkbox, select} from '@inquirer/prompts';
import {
CodeArtifact,
ConfigFile,
Expand All @@ -12,6 +12,7 @@ import {
PoolCache,
PoolConfigs,
PoolIdentifier,
VOTING_NETWORK,
} from './types';
import {flashBorrower} from './features/flashBorrower';
import {capsUpdates} from './features/capsUpdates';
Expand Down Expand Up @@ -39,6 +40,12 @@ program
.addOption(new Option('-a, --author <string>', 'author'))
.addOption(new Option('-d, --discussion <string>', 'forum link'))
.addOption(new Option('-s, --snapshot <string>', 'snapshot link'))
.addOption(
new Option(
'-v, --votingNetwork <votingNetwork...>',
'network where voting should take place for the proposal',
).choices(Object.values(VOTING_NETWORK)),
)
.addOption(new Option('-c, --configFile <string>', 'path to config file'))
.allowExcessArguments(false)
.parse(process.argv);
Expand Down Expand Up @@ -194,6 +201,17 @@ if (options.configFile) {
});
}

if (!options.votingNetwork) {
options.votingNetwork = await select({
message: 'Select network where voting should takes place for the proposal',
choices: Object.values(VOTING_NETWORK).map((v) => ({
name: v != VOTING_NETWORK.POLYGON ? v : VOTING_NETWORK.POLYGON + ' (DEFAULT)',
value: v,
})),
default: VOTING_NETWORK.POLYGON,
});
}

for (const pool of options.pools) {
await fetchPoolOptions(pool);
}
Expand Down
11 changes: 10 additions & 1 deletion generator/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as addressBook from '@bgd-labs/aave-address-book';
import {Options, PoolIdentifier, PoolIdentifierV3, V2_POOLS} from './types';
import {Options, PoolIdentifier, PoolIdentifierV3, V2_POOLS, VOTING_NETWORK} from './types';
import {
arbitrum,
avalanche,
Expand Down Expand Up @@ -60,6 +60,15 @@ export function getDate() {
return `${years}${months <= 9 ? '0' : ''}${months}${day <= 9 ? '0' : ''}${day}`;
}

export function getVotingPortal(votingNetwork?: VOTING_NETWORK) {
if (votingNetwork == VOTING_NETWORK.ETHEREUM) {
return 'GovernanceV3Ethereum.VOTING_PORTAL_ETH_ETH';
} else if (votingNetwork == VOTING_NETWORK.AVALANCHE) {
return 'GovernanceV3Ethereum.VOTING_PORTAL_ETH_AVAX';
}
return 'GovernanceV3Ethereum.VOTING_PORTAL_ETH_POL'; // default voting network is polygon
}

/**
* Prefix with the date for proper sorting
* @param {*} options
Expand Down
2 changes: 2 additions & 0 deletions generator/features/__snapshots__/assetListing.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
pragma solidity ^0.8.0;
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {EthereumScript} from 'aave-helpers/ScriptUtils.sol';
import {AaveV3Ethereum_Test_20231023} from './AaveV3Ethereum_Test_20231023.sol';
Expand Down Expand Up @@ -267,6 +268,7 @@ contract CreateProposal is EthereumScript {
GovV3Helpers.createProposal(
vm,
payloads,
GovernanceV3Ethereum.VOTING_PORTAL_ETH_POL,
GovV3Helpers.ipfsHashFile(vm, 'src/20231023_AaveV3Ethereum_Test/Test.md')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
pragma solidity ^0.8.0;
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {EthereumScript} from 'aave-helpers/ScriptUtils.sol';
import {AaveV3Ethereum_Test_20231023} from './AaveV3Ethereum_Test_20231023.sol';
Expand Down Expand Up @@ -163,6 +164,7 @@ contract CreateProposal is EthereumScript {
GovV3Helpers.createProposal(
vm,
payloads,
GovernanceV3Ethereum.VOTING_PORTAL_ETH_POL,
GovV3Helpers.ipfsHashFile(vm, 'src/20231023_AaveV3Ethereum_Test/Test.md')
);
}
Expand Down
2 changes: 2 additions & 0 deletions generator/features/__snapshots__/rateUpdates.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ contract AaveV2EthereumAMM_Test_20231023_Test is ProtocolV2TestBase {
pragma solidity ^0.8.0;
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {EthereumScript} from 'aave-helpers/ScriptUtils.sol';
import {AaveV2EthereumAMM_Test_20231023} from './AaveV2EthereumAMM_Test_20231023.sol';
Expand Down Expand Up @@ -271,6 +272,7 @@ contract CreateProposal is EthereumScript {
GovV3Helpers.createProposal(
vm,
payloads,
GovernanceV3Ethereum.VOTING_PORTAL_ETH_POL,
GovV3Helpers.ipfsHashFile(vm, 'src/20231023_AaveV2EthereumAMM_Test/Test.md')
);
}
Expand Down
4 changes: 3 additions & 1 deletion generator/templates/script.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
generateFolderName,
getChainAlias,
getPoolChain,
getVotingPortal,
} from '../common';
import {Options} from '../types';
import {prefixWithImports} from '../utils/importsResolver';
Expand All @@ -12,6 +13,7 @@ import {prefixWithPragma} from '../utils/constants';
export function generateScript(options: Options) {
const folderName = generateFolderName(options);
const fileName = generateContractName(options);
const votingPortal = getVotingPortal(options.votingNetwork);
let template = '';
const chains = [...new Set(options.pools.map((pool) => getPoolChain(pool)!))];

Expand Down Expand Up @@ -105,7 +107,7 @@ contract CreateProposal is EthereumScript {
// create proposal
vm.startBroadcast();
GovV3Helpers.createProposal(vm, payloads, GovV3Helpers.ipfsHashFile(vm, 'src/${folderName}/${
GovV3Helpers.createProposal(vm, payloads, ${votingPortal}, GovV3Helpers.ipfsHashFile(vm, 'src/${folderName}/${
options.shortName
}.md'));
}
Expand Down
7 changes: 7 additions & 0 deletions generator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface Options {
force?: boolean;
pools: PoolIdentifier[];
title: string;
votingNetwork?: VOTING_NETWORK;
// automatically generated shortName from title
shortName: string;
author: string;
Expand Down Expand Up @@ -87,6 +88,12 @@ export enum FEATURE {
OTHERS = 'OTHERS',
}

export enum VOTING_NETWORK {
POLYGON = 'POLYGON',
ETHEREUM = 'ETHEREUM',
AVALANCHE = 'AVALANCHE',
}

export interface FeatureModule<T extends {} = {}> {
description: string;
value: FEATURE;
Expand Down
3 changes: 3 additions & 0 deletions generator/utils/importsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export function prefixWithImports(code: string) {
if (findMatch(code, 'forceApprove')) {
imports += `import {SafeERC20} from 'solidity-utils/contracts/oz-common/SafeERC20.sol';\n`;
}
if (findMatch(code, 'GovernanceV3Ethereum')) {
imports += `import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';\n`;
}

return imports + code;
}

0 comments on commit 410c8c5

Please sign in to comment.