From 3454783ff52c3138bcd495c9f7e2ad0fbf7bf9e0 Mon Sep 17 00:00:00 2001 From: Harsh Pandey Date: Sun, 29 Oct 2023 17:53:52 +0530 Subject: [PATCH] fix: use forceApprove on generator for assetListing --- generator/features/assetListing.ts | 4 ++-- generator/templates/proposal.template.ts | 9 +++++++-- generator/utils/importsResolver.ts | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/generator/features/assetListing.ts b/generator/features/assetListing.ts index c8cfc8785..14f0c185e 100644 --- a/generator/features/assetListing.ts +++ b/generator/features/assetListing.ts @@ -105,7 +105,7 @@ export const assetListing: FeatureModule = { ), execute: cfg.map( (cfg) => - `IERC20(${cfg.assetSymbol}).approve(address(${pool}.POOL), 10 * ${cfg.decimals}); + `IERC20(${cfg.assetSymbol}).forceApprove(address(${pool}.POOL), 10 * ${cfg.decimals}); ${pool}.POOL.supply(${cfg.assetSymbol}, 10 ** ${cfg.decimals}, address(${pool}.COLLECTOR), 0);` ), fn: [ @@ -187,7 +187,7 @@ export const assetListingCustom: FeatureModule = { ), execute: cfg.map( (cfg) => - `IERC20(${cfg.base.assetSymbol}).approve(address(${pool}.POOL), 10 * ${cfg.base.decimals}); + `IERC20(${cfg.base.assetSymbol}).forceApprove(address(${pool}.POOL), 10 * ${cfg.base.decimals}); ${pool}.POOL.supply(${cfg.base.assetSymbol}, 10 ** ${cfg.base.decimals}, ${pool}.COLLECTOR, 0);` ), fn: [ diff --git a/generator/templates/proposal.template.ts b/generator/templates/proposal.template.ts index 97ad23f80..5f37267d2 100644 --- a/generator/templates/proposal.template.ts +++ b/generator/templates/proposal.template.ts @@ -29,6 +29,9 @@ export const proposalTemplate = (options: Options, poolConfig: PoolConfig) => { const usesConfigEngine = poolConfig.features.some( (f) => ![FEATURE.OTHERS, FEATURE.FLASH_BORROWER].includes(f) ); + const isAssetListing = poolConfig.features.some( + (f) => [FEATURE.ASSET_LISTING, FEATURE.ASSET_LISTING_CUSTOM].includes(f) + ); if (innerExecute) { if (usesConfigEngine) { optionalExecute = `function _postExecute() internal override { @@ -50,10 +53,12 @@ export const proposalTemplate = (options: Options, poolConfig: PoolConfig) => { contract ${contractName} is ${ usesConfigEngine ? `Aave${version}Payload${chain}` : 'IProposalGenericExecutor' } { + ${isAssetListing ? 'using SafeERC20 for IERC20;' : ''} + ${constants} - + ${optionalExecute} - + ${functions} }`; diff --git a/generator/utils/importsResolver.ts b/generator/utils/importsResolver.ts index 5fb7a25dd..304ee3f5a 100644 --- a/generator/utils/importsResolver.ts +++ b/generator/utils/importsResolver.ts @@ -97,6 +97,9 @@ export function prefixWithImports(code: string) { if (findMatch(code, 'IERC20')) { imports += `import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol';\n`; } + if (findMatch(code, 'forceApprove')) { + imports += `import {SafeERC20} from 'solidity-utils/contracts/oz-common/SafeERC20.sol';\n`; + } return imports + code; }