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'); + } +}