From 8aa8b710e08b64dbf05732d91def34bda9125a31 Mon Sep 17 00:00:00 2001 From: sakulstra Date: Thu, 26 Oct 2023 00:14:38 +0200 Subject: [PATCH] fix: some minor patches --- .../__snapshots__/assetListing.spec.ts.snap | 20 +++++++++++-------- generator/features/assetListing.ts | 4 ++-- generator/prompts.ts | 1 + generator/utils/importsResolver.spec.ts | 6 ++++++ generator/utils/importsResolver.ts | 8 ++++++-- remappings.txt | 2 +- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/generator/features/__snapshots__/assetListing.spec.ts.snap b/generator/features/__snapshots__/assetListing.spec.ts.snap index 428e19738..53000c16d 100644 --- a/generator/features/__snapshots__/assetListing.spec.ts.snap +++ b/generator/features/__snapshots__/assetListing.spec.ts.snap @@ -89,6 +89,7 @@ pragma solidity ^0.8.0; import {AaveV3Ethereum, AaveV3EthereumEModes} from 'aave-address-book/AaveV3Ethereum.sol'; import {AaveV3PayloadEthereum} from 'aave-helpers/v3-config-engine/AaveV3PayloadEthereum.sol'; import {IAaveV3ConfigEngine} from 'aave-helpers/v3-config-engine/IAaveV3ConfigEngine.sol'; +import {IV3RateStrategyFactory} from 'aave-helpers/v3-config-engine/IV3RateStrategyFactory.sol'; /** * @title test @@ -100,7 +101,7 @@ contract AaveV3Ethereum_Test_20231023 is AaveV3PayloadEthereum { address public constant PSP = address(0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5); function _postExecute() internal override { - AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, AaveV3Ethereum.COLLECTOR, 0); + AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, address(AaveV3Ethereum.COLLECTOR), 0); } function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) { @@ -124,7 +125,7 @@ contract AaveV3Ethereum_Test_20231023 is AaveV3PayloadEthereum { borrowCap: 5_000, debtCeiling: 100_000, liqProtocolFee: 20_00, - rateStrategyParams: Rates.RateStrategyParams({ + rateStrategyParams: IV3RateStrategyFactory.RateStrategyParams({ optimalUsageRatio: _bpsToRay(80_00), baseVariableBorrowRate: _bpsToRay(0_00), variableRateSlope1: _bpsToRay(10_00), @@ -146,6 +147,7 @@ pragma solidity ^0.8.0; import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol'; import {AaveV3Ethereum} from 'aave-address-book/AaveV3Ethereum.sol'; +import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol'; import 'forge-std/Test.sol'; import {ProtocolV3TestBase, ReserveConfig} from 'aave-helpers/ProtocolV3TestBase.sol'; @@ -159,7 +161,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18420741); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18430155); proposal = new AaveV3Ethereum_Test_20231023(); } @@ -172,8 +174,10 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { function test_collectorHasPSPFunds() public { GovV3Helpers.executePayload(vm, address(proposal)); - assertGte( - IERC20(0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5).balanceOf(AaveV3Ethereum.COLLECTOR), + assertGe( + IERC20(0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5).balanceOf( + address(AaveV3Ethereum.COLLECTOR) + ), 10 ** 18 ); } @@ -240,7 +244,7 @@ exports[`feature: assetListing > should return reasonable code 1`] = ` "address public constant PSP = address(0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5);", ], "execute": [ - "AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, AaveV3Ethereum.COLLECTOR, 0);", + "AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, address(AaveV3Ethereum.COLLECTOR), 0);", ], "fn": [ "function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) { @@ -264,7 +268,7 @@ exports[`feature: assetListing > should return reasonable code 1`] = ` borrowCap: 5_000, debtCeiling: 100_000, liqProtocolFee: 20_00, - rateStrategyParams: Rates.RateStrategyParams({ + rateStrategyParams: IV3RateStrategyFactory.RateStrategyParams({ optimalUsageRatio: _bpsToRay(80_00), baseVariableBorrowRate: _bpsToRay(0_00), variableRateSlope1: _bpsToRay(10_00), @@ -285,7 +289,7 @@ exports[`feature: assetListing > should return reasonable code 1`] = ` "fn": [ "function test_collectorHasPSPFunds() public { GovV3Helpers.executePayload(vm,address(proposal)); - assertGte(IERC20(0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5).balanceOf(AaveV3Ethereum.COLLECTOR), 10 ** 18); + assertGe(IERC20(0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5).balanceOf(address(AaveV3Ethereum.COLLECTOR)), 10 ** 18); }", ], }, diff --git a/generator/features/assetListing.ts b/generator/features/assetListing.ts index 6fe1b2322..a664d2a99 100644 --- a/generator/features/assetListing.ts +++ b/generator/features/assetListing.ts @@ -105,7 +105,7 @@ export const assetListing: FeatureModule = { ), execute: cfg.map( (cfg) => - `${pool}.POOL.supply(${cfg.assetSymbol}, 10 ** ${cfg.decimals}, ${pool}.COLLECTOR, 0);` + `${pool}.POOL.supply(${cfg.assetSymbol}, 10 ** ${cfg.decimals}, address(${pool}.COLLECTOR), 0);` ), fn: [ `function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) { @@ -156,7 +156,7 @@ export const assetListing: FeatureModule = { fn: cfg.map( (cfg) => `function test_collectorHas${cfg.assetSymbol}Funds() public { ${TEST_EXECUTE_PROPOSAL} - assertGte(IERC20(${cfg.asset}).balanceOf(${pool}.COLLECTOR), 10 ** ${cfg.decimals}); + assertGe(IERC20(${cfg.asset}).balanceOf(address(${pool}.COLLECTOR)), 10 ** ${cfg.decimals}); }` ), }, diff --git a/generator/prompts.ts b/generator/prompts.ts index 9fa25ce3e..0c682c86a 100644 --- a/generator/prompts.ts +++ b/generator/prompts.ts @@ -52,6 +52,7 @@ function translateJsAddressToSol(value: string) { } function translateJsBoolToSol(value: string) { + console.log(value); switch (value) { case ENGINE_FLAGS.ENABLED: return `EngineFlags.ENABLED`; diff --git a/generator/utils/importsResolver.spec.ts b/generator/utils/importsResolver.spec.ts index e70ff2190..400ba34e8 100644 --- a/generator/utils/importsResolver.spec.ts +++ b/generator/utils/importsResolver.spec.ts @@ -3,6 +3,12 @@ import {expect, describe, it} from 'vitest'; import {prefixWithImports} from './importsResolver'; describe('prefixWithImports', () => { + it('should resolve IProposalGenericExecutor', () => { + expect(prefixWithImports(`is IProposalGenericExecutor {`)).toContain( + `import {IProposalGenericExecutor} from 'aave-helpers/interfaces/IProposalGenericExecutor.sol';` + ); + }); + it('should resolve Engine imports', () => { expect(prefixWithImports(`GovV3Helpers.createPayload`)).toContain( `import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';` diff --git a/generator/utils/importsResolver.ts b/generator/utils/importsResolver.ts index da10361c8..5fb7a25dd 100644 --- a/generator/utils/importsResolver.ts +++ b/generator/utils/importsResolver.ts @@ -44,11 +44,11 @@ function generateEngineImport(code: string) { } function findMatches(code: string, needles: string[] | readonly string[]) { - return needles.filter((needle) => RegExp(needle + '\\.', 'g').test(code)); + return needles.filter((needle) => RegExp(needle, 'g').test(code)); } function findMatch(code: string, needle: string) { - return RegExp(needle + '\\.', 'g').test(code); + return RegExp(needle, 'g').test(code); } /** @@ -93,6 +93,10 @@ export function prefixWithImports(code: string) { if (findMatch(code, 'IV2RateStrategyFactory')) { imports += `import {IV2RateStrategyFactory} from 'aave-helpers/v2-config-engine/IV2RateStrategyFactory.sol';\n`; } + // common imports + if (findMatch(code, 'IERC20')) { + imports += `import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol';\n`; + } return imports + code; } diff --git a/remappings.txt b/remappings.txt index 8d53e4d37..a448a27c0 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,6 +1,6 @@ @aave/core-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core/ @aave/periphery-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-periphery/ -aave-address-book/=lib/aave-address-book/src/ +aave-address-book/=lib/aave-helpers/lib/lib/aave-address-book/src/ aave-helpers/=lib/aave-helpers/src/ aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core/ aave-v3-periphery/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-periphery/