From 26d0ab2a328d737824c0fddbb366c718ff670d1a Mon Sep 17 00:00:00 2001 From: sakulstra Date: Thu, 2 Nov 2023 16:16:36 +0100 Subject: [PATCH 1/4] feat: generate specification --- .../__snapshots__/assetListing.spec.ts.snap | 66 ++++++++++++++++++- .../priceFeedsUpdate.spec.ts.snap | 2 +- generator/features/assetListing.ts | 37 ++++++++++- generator/templates/aip.template.ts | 8 +-- 4 files changed, 105 insertions(+), 8 deletions(-) diff --git a/generator/features/__snapshots__/assetListing.spec.ts.snap b/generator/features/__snapshots__/assetListing.spec.ts.snap index d713c080a..216053411 100644 --- a/generator/features/__snapshots__/assetListing.spec.ts.snap +++ b/generator/features/__snapshots__/assetListing.spec.ts.snap @@ -14,6 +14,36 @@ discussions: \\"test\\" ## Specification +The table below illustrates the configured risk parameters for **PSP** + +| Parameter | Value | +| ---------------------------------- | -----------------------------------------: | +| Isolation Mode | true | +| Borrowable | EngineFlags.ENABLED | +| Collateral Enabled | true | +| Supply Cap (PSP) | 10_000 | +| Borrow Cap (PSP) | 5_000 | +| Debt Ceiling | 100_000 | +| LTV | 40_00 | +| LT | 50_00 | +| Liquidation Bonus | 5_00 | +| Liquidation Protocol Fee | 20_00 | +| Reserve Factor | 20_00 | +| Base Variable Borrow Rate | \\\\_bpsToRay(0) | +| Variable Slope 1 | \\\\_bpsToRay(10_00) | +| Variable Slope 2 | \\\\_bpsToRay(100_00) | +| Uoptimal | \\\\_bpsToRay(80_00) | +| Stable Borrowing | EngineFlags.DISABLED | +| Stable Slope1 | \\\\_bpsToRay(10_00) | +| Stable Slope2 | \\\\_bpsToRay(100_00) | +| Base Stable Rate Offset | \\\\_bpsToRay(1_00) | +| Stable Rate Excess Offset | \\\\_bpsToRay(0) | +| Optimal Stable To Total Debt Ratio | \\\\_bpsToRay(10_00) | +| Flahloanable | EngineFlags.ENABLED | +| Siloed Borrowing | EngineFlags.DISABLED | +| Borrowable in Isolation | EngineFlags.DISABLED | +| Oracle | 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8 | + ## References - Implementation: [AaveV3Ethereum](https://github.com/bgd-labs/aave-proposals-v3/blob/main/src/20231023_AaveV3Ethereum_Test/AaveV3Ethereum_Test_20231023.sol) @@ -168,7 +198,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18487480); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18532972); proposal = new AaveV3Ethereum_Test_20231023(); } @@ -245,6 +275,40 @@ contract CreateProposal is EthereumScript { exports[`feature: assetListing > should return reasonable code 1`] = ` { + "aip": { + "specification": [ + "The table below illustrates the configured risk parameters for **PSP** + +| Parameter | Value | +| --- | --: | +| Isolation Mode | true | +| Borrowable | EngineFlags.ENABLED | +| Collateral Enabled | true | +| Supply Cap (PSP) | 10_000 | +| Borrow Cap (PSP) | 5_000 | +| Debt Ceiling | 100_000 | +| LTV | 40_00 | +| LT | 50_00 | +| Liquidation Bonus | 5_00 | +| Liquidation Protocol Fee | 20_00 | +| Reserve Factor | 20_00 | +| Base Variable Borrow Rate | _bpsToRay(0) | +| Variable Slope 1 | _bpsToRay(10_00) | +| Variable Slope 2 | _bpsToRay(100_00) | +| Uoptimal | _bpsToRay(80_00) | +| Stable Borrowing | EngineFlags.DISABLED | +| Stable Slope1 | _bpsToRay(10_00) | +| Stable Slope2 | _bpsToRay(100_00) | +| Base Stable Rate Offset | _bpsToRay(1_00) | +| Stable Rate Excess Offset | _bpsToRay(0) | +| Optimal Stable To Total Debt Ratio | _bpsToRay(10_00) | +| Flahloanable | EngineFlags.ENABLED | +| Siloed Borrowing | EngineFlags.DISABLED | +| Borrowable in Isolation | EngineFlags.DISABLED | +| Oracle | 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8 | +", + ], + }, "code": { "constants": [ "address public constant PSP = 0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5;", diff --git a/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap b/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap index 7787856d3..fe7b18c69 100644 --- a/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap +++ b/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap @@ -105,7 +105,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18487480); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18532972); proposal = new AaveV3Ethereum_Test_20231023(); } diff --git a/generator/features/assetListing.ts b/generator/features/assetListing.ts index 960a72394..55347b9c1 100644 --- a/generator/features/assetListing.ts +++ b/generator/features/assetListing.ts @@ -169,6 +169,39 @@ export const assetListing: FeatureModule = { }` ), }, + aip: { + specification: cfg.map((cfg) => { + let listingTemplate = `The table below illustrates the configured risk parameters for **${cfg.assetSymbol}**\n\n`; + listingTemplate += `| Parameter | Value |\n`; + listingTemplate += `| --- | --: |\n`; + listingTemplate += `| Isolation Mode | ${!!cfg.debtCeiling} |\n`; + listingTemplate += `| Borrowable | ${cfg.enabledToBorrow} |\n`; + listingTemplate += `| Collateral Enabled | ${!!cfg.liqThreshold} |\n`; + listingTemplate += `| Supply Cap (${cfg.assetSymbol}) | ${cfg.supplyCap} |\n`; + listingTemplate += `| Borrow Cap (${cfg.assetSymbol}) | ${cfg.borrowCap} |\n`; + listingTemplate += `| Debt Ceiling | ${cfg.debtCeiling} |\n`; + listingTemplate += `| LTV | ${cfg.ltv} |\n`; + listingTemplate += `| LT | ${cfg.liqThreshold} |\n`; + listingTemplate += `| Liquidation Bonus | ${cfg.liqBonus} |\n`; + listingTemplate += `| Liquidation Protocol Fee | ${cfg.liqProtocolFee} |\n`; + listingTemplate += `| Reserve Factor | ${cfg.reserveFactor} |\n`; + listingTemplate += `| Base Variable Borrow Rate | ${cfg.rateStrategyParams.baseVariableBorrowRate} |\n`; + listingTemplate += `| Variable Slope 1 | ${cfg.rateStrategyParams.variableRateSlope1} |\n`; + listingTemplate += `| Variable Slope 2 | ${cfg.rateStrategyParams.variableRateSlope2} |\n`; + listingTemplate += `| Uoptimal | ${cfg.rateStrategyParams.optimalUtilizationRate} |\n`; + listingTemplate += `| Stable Borrowing | ${cfg.stableRateModeEnabled} |\n`; + listingTemplate += `| Stable Slope1 | ${cfg.rateStrategyParams.stableRateSlope1} |\n`; + listingTemplate += `| Stable Slope2 | ${cfg.rateStrategyParams.stableRateSlope2} |\n`; + listingTemplate += `| Base Stable Rate Offset | ${cfg.rateStrategyParams.baseStableRateOffset} |\n`; + listingTemplate += `| Stable Rate Excess Offset | ${cfg.rateStrategyParams.stableRateExcessOffset} |\n`; + listingTemplate += `| Optimal Stable To Total Debt Ratio | ${cfg.rateStrategyParams.optimalStableToTotalDebtRatio} |\n`; + listingTemplate += `| Flahloanable | ${cfg.flashloanable} |\n`; + listingTemplate += `| Siloed Borrowing | ${cfg.withSiloedBorrowing} |\n`; + listingTemplate += `| Borrowable in Isolation | ${cfg.borrowableInIsolation} |\n`; + listingTemplate += `| Oracle | ${cfg.priceFeed} |\n`; + return listingTemplate; + }), + }, }; return response; }, @@ -210,8 +243,8 @@ export const assetListingCustom: FeatureModule = { .map( (cfg, ix) => `listings[${ix}] = IAaveV3ConfigEngine.ListingWithCustomImpl( IAaveV3ConfigEngine.Listing({ - asset: ${cfg.base.assetSymbol}, - assetSymbol: "${cfg.base.assetSymbol}", + asset: ${cfg.base.assetSymbol}, + assetSymbol: "${cfg.base.assetSymbol}", priceFeed: ${translateJsAddressToSol(cfg.base.priceFeed)}, eModeCategory: ${cfg.base.eModeCategory}, enabledToBorrow: ${cfg.base.enabledToBorrow}, diff --git a/generator/templates/aip.template.ts b/generator/templates/aip.template.ts index 25eff0a65..5a375ff6c 100644 --- a/generator/templates/aip.template.ts +++ b/generator/templates/aip.template.ts @@ -1,5 +1,5 @@ import {generateContractName, generateFolderName} from '../common'; -import {Options, PoolConfigs} from '../types'; +import {Options, PoolConfigs, PoolIdentifier} from '../types'; export function generateAIP(options: Options, configs: PoolConfigs) { return `--- @@ -16,9 +16,9 @@ discussions: ${`"${options.discussion}"` || 'TODO'} ${Object.keys(configs) .map((pool) => { - return configs[pool].artifacts - .filter((artifact) => artifact.aip) - .map((artifact) => artifact.aip); + return configs[pool as keyof typeof configs]!.artifacts.filter( + (artifact) => artifact.aip?.specification + ).map((artifact) => artifact.aip?.specification); }) .filter((a) => a) .join('\n\n')} From 25460194534c091959b48a81a7c2004314b8b0b4 Mon Sep 17 00:00:00 2001 From: sakulstra Date: Thu, 9 Nov 2023 08:44:52 +0100 Subject: [PATCH 2/4] fix: update snapshot --- generator/features/__snapshots__/assetListing.spec.ts.snap | 2 +- generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/features/__snapshots__/assetListing.spec.ts.snap b/generator/features/__snapshots__/assetListing.spec.ts.snap index 216053411..1196b9bac 100644 --- a/generator/features/__snapshots__/assetListing.spec.ts.snap +++ b/generator/features/__snapshots__/assetListing.spec.ts.snap @@ -198,7 +198,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18532972); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18532977); proposal = new AaveV3Ethereum_Test_20231023(); } diff --git a/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap b/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap index fe7b18c69..71bed3eef 100644 --- a/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap +++ b/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap @@ -105,7 +105,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18532972); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18532977); proposal = new AaveV3Ethereum_Test_20231023(); } From 780b9c8413205f35799ad6c1e27edf82fe6ad3f0 Mon Sep 17 00:00:00 2001 From: sakulstra Date: Thu, 9 Nov 2023 09:36:18 +0100 Subject: [PATCH 3/4] comment: comment out aip for now --- generator/features/assetListing.ts | 66 ++++++++++++++-------------- generator/features/borrowsUpdates.ts | 37 ++++++++-------- generator/features/mocks/configs.ts | 10 ++--- generator/prompts.ts | 45 ++----------------- generator/prompts/boolPrompt.ts | 44 +++++++++++++++++++ 5 files changed, 104 insertions(+), 98 deletions(-) create mode 100644 generator/prompts/boolPrompt.ts diff --git a/generator/features/assetListing.ts b/generator/features/assetListing.ts index 55347b9c1..08dc571b7 100644 --- a/generator/features/assetListing.ts +++ b/generator/features/assetListing.ts @@ -169,39 +169,39 @@ export const assetListing: FeatureModule = { }` ), }, - aip: { - specification: cfg.map((cfg) => { - let listingTemplate = `The table below illustrates the configured risk parameters for **${cfg.assetSymbol}**\n\n`; - listingTemplate += `| Parameter | Value |\n`; - listingTemplate += `| --- | --: |\n`; - listingTemplate += `| Isolation Mode | ${!!cfg.debtCeiling} |\n`; - listingTemplate += `| Borrowable | ${cfg.enabledToBorrow} |\n`; - listingTemplate += `| Collateral Enabled | ${!!cfg.liqThreshold} |\n`; - listingTemplate += `| Supply Cap (${cfg.assetSymbol}) | ${cfg.supplyCap} |\n`; - listingTemplate += `| Borrow Cap (${cfg.assetSymbol}) | ${cfg.borrowCap} |\n`; - listingTemplate += `| Debt Ceiling | ${cfg.debtCeiling} |\n`; - listingTemplate += `| LTV | ${cfg.ltv} |\n`; - listingTemplate += `| LT | ${cfg.liqThreshold} |\n`; - listingTemplate += `| Liquidation Bonus | ${cfg.liqBonus} |\n`; - listingTemplate += `| Liquidation Protocol Fee | ${cfg.liqProtocolFee} |\n`; - listingTemplate += `| Reserve Factor | ${cfg.reserveFactor} |\n`; - listingTemplate += `| Base Variable Borrow Rate | ${cfg.rateStrategyParams.baseVariableBorrowRate} |\n`; - listingTemplate += `| Variable Slope 1 | ${cfg.rateStrategyParams.variableRateSlope1} |\n`; - listingTemplate += `| Variable Slope 2 | ${cfg.rateStrategyParams.variableRateSlope2} |\n`; - listingTemplate += `| Uoptimal | ${cfg.rateStrategyParams.optimalUtilizationRate} |\n`; - listingTemplate += `| Stable Borrowing | ${cfg.stableRateModeEnabled} |\n`; - listingTemplate += `| Stable Slope1 | ${cfg.rateStrategyParams.stableRateSlope1} |\n`; - listingTemplate += `| Stable Slope2 | ${cfg.rateStrategyParams.stableRateSlope2} |\n`; - listingTemplate += `| Base Stable Rate Offset | ${cfg.rateStrategyParams.baseStableRateOffset} |\n`; - listingTemplate += `| Stable Rate Excess Offset | ${cfg.rateStrategyParams.stableRateExcessOffset} |\n`; - listingTemplate += `| Optimal Stable To Total Debt Ratio | ${cfg.rateStrategyParams.optimalStableToTotalDebtRatio} |\n`; - listingTemplate += `| Flahloanable | ${cfg.flashloanable} |\n`; - listingTemplate += `| Siloed Borrowing | ${cfg.withSiloedBorrowing} |\n`; - listingTemplate += `| Borrowable in Isolation | ${cfg.borrowableInIsolation} |\n`; - listingTemplate += `| Oracle | ${cfg.priceFeed} |\n`; - return listingTemplate; - }), - }, + // aip: { + // specification: cfg.map((cfg) => { + // let listingTemplate = `The table below illustrates the configured risk parameters for **${cfg.assetSymbol}**\n\n`; + // listingTemplate += `| Parameter | Value |\n`; + // listingTemplate += `| --- | --: |\n`; + // listingTemplate += `| Isolation Mode | ${!!cfg.debtCeiling} |\n`; + // listingTemplate += `| Borrowable | ${cfg.enabledToBorrow} |\n`; + // listingTemplate += `| Collateral Enabled | ${!!cfg.liqThreshold} |\n`; + // listingTemplate += `| Supply Cap (${cfg.assetSymbol}) | ${cfg.supplyCap} |\n`; + // listingTemplate += `| Borrow Cap (${cfg.assetSymbol}) | ${cfg.borrowCap} |\n`; + // listingTemplate += `| Debt Ceiling | ${cfg.debtCeiling} |\n`; + // listingTemplate += `| LTV | ${cfg.ltv} |\n`; + // listingTemplate += `| LT | ${cfg.liqThreshold} |\n`; + // listingTemplate += `| Liquidation Bonus | ${cfg.liqBonus} |\n`; + // listingTemplate += `| Liquidation Protocol Fee | ${cfg.liqProtocolFee} |\n`; + // listingTemplate += `| Reserve Factor | ${cfg.reserveFactor} |\n`; + // listingTemplate += `| Base Variable Borrow Rate | ${cfg.rateStrategyParams.baseVariableBorrowRate} |\n`; + // listingTemplate += `| Variable Slope 1 | ${cfg.rateStrategyParams.variableRateSlope1} |\n`; + // listingTemplate += `| Variable Slope 2 | ${cfg.rateStrategyParams.variableRateSlope2} |\n`; + // listingTemplate += `| Uoptimal | ${cfg.rateStrategyParams.optimalUtilizationRate} |\n`; + // listingTemplate += `| Stable Borrowing | ${cfg.stableRateModeEnabled} |\n`; + // listingTemplate += `| Stable Slope1 | ${cfg.rateStrategyParams.stableRateSlope1} |\n`; + // listingTemplate += `| Stable Slope2 | ${cfg.rateStrategyParams.stableRateSlope2} |\n`; + // listingTemplate += `| Base Stable Rate Offset | ${cfg.rateStrategyParams.baseStableRateOffset} |\n`; + // listingTemplate += `| Stable Rate Excess Offset | ${cfg.rateStrategyParams.stableRateExcessOffset} |\n`; + // listingTemplate += `| Optimal Stable To Total Debt Ratio | ${cfg.rateStrategyParams.optimalStableToTotalDebtRatio} |\n`; + // listingTemplate += `| Flahloanable | ${cfg.flashloanable} |\n`; + // listingTemplate += `| Siloed Borrowing | ${cfg.withSiloedBorrowing} |\n`; + // listingTemplate += `| Borrowable in Isolation | ${cfg.borrowableInIsolation} |\n`; + // listingTemplate += `| Oracle | ${cfg.priceFeed} |\n`; + // return listingTemplate; + // }), + // }, }; return response; }, diff --git a/generator/features/borrowsUpdates.ts b/generator/features/borrowsUpdates.ts index cc7af61c8..e265bcf77 100644 --- a/generator/features/borrowsUpdates.ts +++ b/generator/features/borrowsUpdates.ts @@ -1,39 +1,40 @@ import {CodeArtifact, ENGINE_FLAGS, FEATURE, FeatureModule} from '../types'; -import {booleanSelect, percentInput} from '../prompts'; +import {percentInput} from '../prompts'; import {BorrowUpdate} from './types'; import { assetsSelectPrompt, translateAssetToAssetLibUnderlying, } from '../prompts/assetsSelectPrompt'; +import {boolPrompt, translateJsBoolToSol} from '../prompts/boolPrompt'; -export async function fetchBorrowUpdate(disableKeepCurrent?: T) { +export async function fetchBorrowUpdate(required?: T) { return { - enabledToBorrow: await booleanSelect({ + enabledToBorrow: await boolPrompt({ message: 'enabled to borrow', - disableKeepCurrent, + required, }), - flashloanable: await booleanSelect({ + flashloanable: await boolPrompt({ message: 'flashloanable', - disableKeepCurrent, + required, }), - stableRateModeEnabled: await booleanSelect({ + stableRateModeEnabled: await boolPrompt({ message: 'stable rate mode enabled', - disableKeepCurrent, + required, defaultValue: ENGINE_FLAGS.DISABLED, }), - borrowableInIsolation: await booleanSelect({ + borrowableInIsolation: await boolPrompt({ message: 'borrowable in isolation', - disableKeepCurrent, + required, defaultValue: ENGINE_FLAGS.DISABLED, }), - withSiloedBorrowing: await booleanSelect({ + withSiloedBorrowing: await boolPrompt({ message: 'siloed borrowing', - disableKeepCurrent, + required, defaultValue: ENGINE_FLAGS.DISABLED, }), reserveFactor: await percentInput({ message: 'reserve factor', - disableKeepCurrent, + disableKeepCurrent: required, }), }; } @@ -69,11 +70,11 @@ export const borrowsUpdates: FeatureModule = { .map( (cfg, ix) => `borrowUpdates[${ix}] = IAaveV3ConfigEngine.BorrowUpdate({ asset: ${translateAssetToAssetLibUnderlying(cfg.asset, pool)}, - enabledToBorrow: ${cfg.enabledToBorrow}, - flashloanable: ${cfg.flashloanable}, - stableRateModeEnabled: ${cfg.stableRateModeEnabled}, - borrowableInIsolation: ${cfg.borrowableInIsolation}, - withSiloedBorrowing: ${cfg.withSiloedBorrowing}, + enabledToBorrow: ${translateJsBoolToSol(cfg.enabledToBorrow)}, + flashloanable: ${translateJsBoolToSol(cfg.flashloanable)}, + stableRateModeEnabled: ${translateJsBoolToSol(cfg.stableRateModeEnabled)}, + borrowableInIsolation: ${translateJsBoolToSol(cfg.borrowableInIsolation)}, + withSiloedBorrowing: ${translateJsBoolToSol(cfg.withSiloedBorrowing)}, reserveFactor: ${cfg.reserveFactor} });` ) diff --git a/generator/features/mocks/configs.ts b/generator/features/mocks/configs.ts index 007a1658b..d6d7e1a2c 100644 --- a/generator/features/mocks/configs.ts +++ b/generator/features/mocks/configs.ts @@ -21,11 +21,11 @@ export const assetListingConfig: Listing[] = [ liqBonus: '5_00', debtCeiling: '100_000', liqProtocolFee: '20_00', - enabledToBorrow: 'EngineFlags.ENABLED', - flashloanable: 'EngineFlags.ENABLED', - stableRateModeEnabled: 'EngineFlags.DISABLED', - borrowableInIsolation: 'EngineFlags.DISABLED', - withSiloedBorrowing: 'EngineFlags.DISABLED', + enabledToBorrow: 'ENABLED', + flashloanable: 'ENABLED', + stableRateModeEnabled: 'DISABLED', + borrowableInIsolation: 'DISABLED', + withSiloedBorrowing: 'DISABLED', reserveFactor: '20_00', supplyCap: '10_000', borrowCap: '5_000', diff --git a/generator/prompts.ts b/generator/prompts.ts index 34b480346..69446ae50 100644 --- a/generator/prompts.ts +++ b/generator/prompts.ts @@ -1,6 +1,6 @@ -import {checkbox, input, select} from '@inquirer/prompts'; +import {checkbox, select} from '@inquirer/prompts'; import {ENGINE_FLAGS, PoolIdentifier} from './types'; -import {getAssets, getEModes} from './common'; +import {getEModes} from './common'; import {advancedInput} from './prompts/advancedInput'; // VALIDATION @@ -51,19 +51,6 @@ export function translateJsNumberToSol(value: string) { return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, '_'); } -function translateJsBoolToSol(value: string) { - switch (value) { - case ENGINE_FLAGS.ENABLED: - return `EngineFlags.ENABLED`; - case ENGINE_FLAGS.DISABLED: - return `EngineFlags.DISABLED`; - case ENGINE_FLAGS.KEEP_CURRENT: - return `EngineFlags.KEEP_CURRENT`; - default: - return value; - } -} - function translateEModeToEModeLib(value: string, pool: PoolIdentifier) { if (value === ENGINE_FLAGS.KEEP_CURRENT) return `EngineFlags.KEEP_CURRENT`; return `${pool}EModes.${value}`; @@ -77,33 +64,6 @@ interface GenericPrompt { defaultValue?: string; } -export type BooleanSelectValues = - | typeof ENGINE_FLAGS.KEEP_CURRENT - | typeof ENGINE_FLAGS.ENABLED - | typeof ENGINE_FLAGS.DISABLED; - -export async function booleanSelect({ - message, - disableKeepCurrent, - defaultValue, -}: GenericPrompt): Promise< - T extends true ? Exclude : BooleanSelectValues -> { - const choices = [ - ...(disableKeepCurrent ? [] : [{value: ENGINE_FLAGS.KEEP_CURRENT}]), - {value: ENGINE_FLAGS.ENABLED}, - {value: ENGINE_FLAGS.DISABLED}, - ]; - const value = await select({ - message, - choices: choices, - default: defaultValue, - }); - return translateJsBoolToSol(value) as T extends true - ? Exclude - : BooleanSelectValues; -} - interface PercentInputPrompt extends GenericPrompt { toRay?: boolean; } @@ -180,6 +140,7 @@ export async function eModesSelect({message, pool}: EModeSele .filter((e) => e != 'NONE') .map((eMode) => ({value: eMode})), ], + required: true, }); return values.map((mode) => translateEModeToEModeLib(mode, pool)); } else { diff --git a/generator/prompts/boolPrompt.ts b/generator/prompts/boolPrompt.ts new file mode 100644 index 000000000..d73e835f5 --- /dev/null +++ b/generator/prompts/boolPrompt.ts @@ -0,0 +1,44 @@ +import {select} from '@inquirer/prompts'; +import {ENGINE_FLAGS} from '../types'; +import {GenericPrompt} from './types'; + +export type BooleanSelectValues = + | typeof ENGINE_FLAGS.KEEP_CURRENT + | typeof ENGINE_FLAGS.ENABLED + | typeof ENGINE_FLAGS.DISABLED; + +export async function boolPrompt({ + message, + required, + defaultValue, +}: GenericPrompt & { + defaultValue?: T extends true + ? Exclude + : BooleanSelectValues; +}): Promise : BooleanSelectValues> { + const choices = [ + ...(required ? [] : [{value: ENGINE_FLAGS.KEEP_CURRENT}]), + {value: ENGINE_FLAGS.ENABLED}, + {value: ENGINE_FLAGS.DISABLED}, + ]; + return select< + T extends true ? Exclude : BooleanSelectValues + >({ + message, + choices: choices as any, + default: defaultValue, + }); +} + +export function translateJsBoolToSol(value: string) { + switch (value) { + case ENGINE_FLAGS.ENABLED: + return `EngineFlags.ENABLED`; + case ENGINE_FLAGS.DISABLED: + return `EngineFlags.DISABLED`; + case ENGINE_FLAGS.KEEP_CURRENT: + return `EngineFlags.KEEP_CURRENT`; + default: + throw new Error('unknown boolean select value'); + } +} From 11af852e6b9c758c602133ca7859427059700451 Mon Sep 17 00:00:00 2001 From: sakulstra Date: Thu, 9 Nov 2023 09:36:56 +0100 Subject: [PATCH 4/4] fix: update test --- .../__snapshots__/assetListing.spec.ts.snap | 97 +++---------------- .../priceFeedsUpdate.spec.ts.snap | 2 +- 2 files changed, 17 insertions(+), 82 deletions(-) diff --git a/generator/features/__snapshots__/assetListing.spec.ts.snap b/generator/features/__snapshots__/assetListing.spec.ts.snap index 1196b9bac..3dfa34ab4 100644 --- a/generator/features/__snapshots__/assetListing.spec.ts.snap +++ b/generator/features/__snapshots__/assetListing.spec.ts.snap @@ -14,36 +14,6 @@ discussions: \\"test\\" ## Specification -The table below illustrates the configured risk parameters for **PSP** - -| Parameter | Value | -| ---------------------------------- | -----------------------------------------: | -| Isolation Mode | true | -| Borrowable | EngineFlags.ENABLED | -| Collateral Enabled | true | -| Supply Cap (PSP) | 10_000 | -| Borrow Cap (PSP) | 5_000 | -| Debt Ceiling | 100_000 | -| LTV | 40_00 | -| LT | 50_00 | -| Liquidation Bonus | 5_00 | -| Liquidation Protocol Fee | 20_00 | -| Reserve Factor | 20_00 | -| Base Variable Borrow Rate | \\\\_bpsToRay(0) | -| Variable Slope 1 | \\\\_bpsToRay(10_00) | -| Variable Slope 2 | \\\\_bpsToRay(100_00) | -| Uoptimal | \\\\_bpsToRay(80_00) | -| Stable Borrowing | EngineFlags.DISABLED | -| Stable Slope1 | \\\\_bpsToRay(10_00) | -| Stable Slope2 | \\\\_bpsToRay(100_00) | -| Base Stable Rate Offset | \\\\_bpsToRay(1_00) | -| Stable Rate Excess Offset | \\\\_bpsToRay(0) | -| Optimal Stable To Total Debt Ratio | \\\\_bpsToRay(10_00) | -| Flahloanable | EngineFlags.ENABLED | -| Siloed Borrowing | EngineFlags.DISABLED | -| Borrowable in Isolation | EngineFlags.DISABLED | -| Oracle | 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8 | - ## References - Implementation: [AaveV3Ethereum](https://github.com/bgd-labs/aave-proposals-v3/blob/main/src/20231023_AaveV3Ethereum_Test/AaveV3Ethereum_Test_20231023.sol) @@ -80,11 +50,11 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public \\"liqBonus\\": \\"5_00\\", \\"debtCeiling\\": \\"100_000\\", \\"liqProtocolFee\\": \\"20_00\\", - \\"enabledToBorrow\\": \\"EngineFlags.ENABLED\\", - \\"flashloanable\\": \\"EngineFlags.ENABLED\\", - \\"stableRateModeEnabled\\": \\"EngineFlags.DISABLED\\", - \\"borrowableInIsolation\\": \\"EngineFlags.DISABLED\\", - \\"withSiloedBorrowing\\": \\"EngineFlags.DISABLED\\", + \\"enabledToBorrow\\": \\"ENABLED\\", + \\"flashloanable\\": \\"ENABLED\\", + \\"stableRateModeEnabled\\": \\"DISABLED\\", + \\"borrowableInIsolation\\": \\"DISABLED\\", + \\"withSiloedBorrowing\\": \\"DISABLED\\", \\"reserveFactor\\": \\"20_00\\", \\"supplyCap\\": \\"10_000\\", \\"borrowCap\\": \\"5_000\\", @@ -118,7 +88,6 @@ 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 {EngineFlags} from 'aave-helpers/v3-config-engine/EngineFlags.sol'; import {IAaveV3ConfigEngine} from 'aave-helpers/v3-config-engine/IAaveV3ConfigEngine.sol'; import {IV3RateStrategyFactory} from 'aave-helpers/v3-config-engine/IV3RateStrategyFactory.sol'; import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol'; @@ -149,11 +118,11 @@ contract AaveV3Ethereum_Test_20231023 is AaveV3PayloadEthereum { assetSymbol: 'PSP', priceFeed: 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8, eModeCategory: AaveV3EthereumEModes.NONE, - enabledToBorrow: EngineFlags.ENABLED, - stableRateModeEnabled: EngineFlags.DISABLED, - borrowableInIsolation: EngineFlags.DISABLED, - withSiloedBorrowing: EngineFlags.DISABLED, - flashloanable: EngineFlags.ENABLED, + enabledToBorrow: ENABLED, + stableRateModeEnabled: DISABLED, + borrowableInIsolation: DISABLED, + withSiloedBorrowing: DISABLED, + flashloanable: ENABLED, ltv: 40_00, liqThreshold: 50_00, liqBonus: 5_00, @@ -198,7 +167,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18532977); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18533234); proposal = new AaveV3Ethereum_Test_20231023(); } @@ -275,40 +244,6 @@ contract CreateProposal is EthereumScript { exports[`feature: assetListing > should return reasonable code 1`] = ` { - "aip": { - "specification": [ - "The table below illustrates the configured risk parameters for **PSP** - -| Parameter | Value | -| --- | --: | -| Isolation Mode | true | -| Borrowable | EngineFlags.ENABLED | -| Collateral Enabled | true | -| Supply Cap (PSP) | 10_000 | -| Borrow Cap (PSP) | 5_000 | -| Debt Ceiling | 100_000 | -| LTV | 40_00 | -| LT | 50_00 | -| Liquidation Bonus | 5_00 | -| Liquidation Protocol Fee | 20_00 | -| Reserve Factor | 20_00 | -| Base Variable Borrow Rate | _bpsToRay(0) | -| Variable Slope 1 | _bpsToRay(10_00) | -| Variable Slope 2 | _bpsToRay(100_00) | -| Uoptimal | _bpsToRay(80_00) | -| Stable Borrowing | EngineFlags.DISABLED | -| Stable Slope1 | _bpsToRay(10_00) | -| Stable Slope2 | _bpsToRay(100_00) | -| Base Stable Rate Offset | _bpsToRay(1_00) | -| Stable Rate Excess Offset | _bpsToRay(0) | -| Optimal Stable To Total Debt Ratio | _bpsToRay(10_00) | -| Flahloanable | EngineFlags.ENABLED | -| Siloed Borrowing | EngineFlags.DISABLED | -| Borrowable in Isolation | EngineFlags.DISABLED | -| Oracle | 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8 | -", - ], - }, "code": { "constants": [ "address public constant PSP = 0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5;", @@ -327,11 +262,11 @@ exports[`feature: assetListing > should return reasonable code 1`] = ` assetSymbol: \\"PSP\\", priceFeed: 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8, eModeCategory: AaveV3EthereumEModes.NONE, - enabledToBorrow: EngineFlags.ENABLED, - stableRateModeEnabled: EngineFlags.DISABLED, - borrowableInIsolation: EngineFlags.DISABLED, - withSiloedBorrowing: EngineFlags.DISABLED, - flashloanable: EngineFlags.ENABLED, + enabledToBorrow: ENABLED, + stableRateModeEnabled: DISABLED, + borrowableInIsolation: DISABLED, + withSiloedBorrowing: DISABLED, + flashloanable: ENABLED, ltv: 40_00, liqThreshold: 50_00, liqBonus: 5_00, diff --git a/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap b/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap index 71bed3eef..f5121dd41 100644 --- a/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap +++ b/generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap @@ -105,7 +105,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase { AaveV3Ethereum_Test_20231023 internal proposal; function setUp() public { - vm.createSelectFork(vm.rpcUrl('mainnet'), 18532977); + vm.createSelectFork(vm.rpcUrl('mainnet'), 18533234); proposal = new AaveV3Ethereum_Test_20231023(); }