Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleaner seeding code #28

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions generator/features/__snapshots__/assetListing.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ contract AaveV3Ethereum_Test_20231023 is AaveV3PayloadEthereum {
using SafeERC20 for IERC20;

address public constant PSP = 0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5;
uint256 internal constant PSP_SEED_AMOUNT = 10 ** 18;

function _postExecute() internal override {
IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), 10 ** 18);
AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, address(AaveV3Ethereum.COLLECTOR), 0);
IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), PSP_SEED_AMOUNT);
AaveV3Ethereum.POOL.supply(PSP, PSP_SEED_AMOUNT, address(AaveV3Ethereum.COLLECTOR), 0);
}

function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) {
Expand Down Expand Up @@ -166,7 +167,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
AaveV3Ethereum_Test_20231023 internal proposal;

function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), 18461057);
vm.createSelectFork(vm.rpcUrl('mainnet'), 18480118);
proposal = new AaveV3Ethereum_Test_20231023();
}

Expand Down Expand Up @@ -219,7 +220,7 @@ contract DeployEthereum is EthereumScript {
* command: make deploy-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:CreateProposal chain=mainnet
*/
contract CreateProposal is EthereumScript {
function run() external broadcast {
function run() external {
// create payloads
PayloadsControllerUtils.Payload[] memory payloads = new PayloadsControllerUtils.Payload[](1);

Expand All @@ -230,6 +231,7 @@ contract CreateProposal is EthereumScript {
payloads[0] = GovV3Helpers.buildMainnetPayload(vm, actionsEthereum);

// create proposal
vm.startBroadcast();
GovV3Helpers.createProposal2_5(
payloads,
GovV3Helpers.ipfsHashFile(vm, 'src/20231023_AaveV3Ethereum_Test/Test.md')
Expand All @@ -245,10 +247,11 @@ exports[`feature: assetListing > should return reasonable code 1`] = `
"code": {
"constants": [
"address public constant PSP = 0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5;",
"uint256 internal constant PSP_SEED_AMOUNT = 10 ** 18;",
],
"execute": [
"IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), 10 ** 18);
AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, address(AaveV3Ethereum.COLLECTOR), 0);",
"IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), PSP_SEED_AMOUNT);
AaveV3Ethereum.POOL.supply(PSP, PSP_SEED_AMOUNT, address(AaveV3Ethereum.COLLECTOR), 0);",
],
"fn": [
"function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) {
Expand Down
11 changes: 8 additions & 3 deletions generator/features/assetListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ export const assetListing: FeatureModule<Listing[]> = {
build(opt, pool, cfg) {
const response: CodeArtifact = {
code: {
constants: cfg.map((cfg) => `address public constant ${cfg.assetSymbol} = ${cfg.asset};`),
constants: cfg
.map((cfg) => [
`address public constant ${cfg.assetSymbol} = ${cfg.asset};`,
`uint256 internal constant ${cfg.assetSymbol}_SEED_AMOUNT = 10 ** ${cfg.decimals};`,
])
.flat(),
execute: cfg.map(
(cfg) =>
`IERC20(${cfg.assetSymbol}).forceApprove(address(${pool}.POOL), 10 ** ${cfg.decimals});
${pool}.POOL.supply(${cfg.assetSymbol}, 10 ** ${cfg.decimals}, address(${pool}.COLLECTOR), 0);`
`IERC20(${cfg.assetSymbol}).forceApprove(address(${pool}.POOL), ${cfg.assetSymbol}_SEED_AMOUNT);
${pool}.POOL.supply(${cfg.assetSymbol}, ${cfg.assetSymbol}_SEED_AMOUNT, address(${pool}.COLLECTOR), 0);`
),
fn: [
`function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) {
Expand Down