Skip to content

Commit

Permalink
fix: use forceApprove on generator for assetListing
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlymite committed Oct 29, 2023
1 parent 1bad653 commit 3454783
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions generator/features/assetListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const assetListing: FeatureModule<Listing[]> = {
),
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: [
Expand Down Expand Up @@ -187,7 +187,7 @@ export const assetListingCustom: FeatureModule<ListingWithCustomImpl[]> = {
),
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: [
Expand Down
9 changes: 7 additions & 2 deletions generator/templates/proposal.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}
}`;

Expand Down
3 changes: 3 additions & 0 deletions generator/utils/importsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 3454783

Please sign in to comment.