Skip to content

Commit

Permalink
comment: comment out aip for now
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Nov 9, 2023
1 parent 2546019 commit 780b9c8
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 98 deletions.
66 changes: 33 additions & 33 deletions generator/features/assetListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,39 +169,39 @@ export const assetListing: FeatureModule<Listing[]> = {
}`
),
},
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;
},
Expand Down
37 changes: 19 additions & 18 deletions generator/features/borrowsUpdates.ts
Original file line number Diff line number Diff line change
@@ -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<T extends boolean>(disableKeepCurrent?: T) {
export async function fetchBorrowUpdate<T extends boolean>(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,
}),
};
}
Expand Down Expand Up @@ -69,11 +70,11 @@ export const borrowsUpdates: FeatureModule<BorrowUpdates> = {
.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}
});`
)
Expand Down
10 changes: 5 additions & 5 deletions generator/features/mocks/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
45 changes: 3 additions & 42 deletions generator/prompts.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}`;
Expand All @@ -77,33 +64,6 @@ interface GenericPrompt<T extends boolean = boolean> {
defaultValue?: string;
}

export type BooleanSelectValues =
| typeof ENGINE_FLAGS.KEEP_CURRENT
| typeof ENGINE_FLAGS.ENABLED
| typeof ENGINE_FLAGS.DISABLED;

export async function booleanSelect<T extends boolean>({
message,
disableKeepCurrent,
defaultValue,
}: GenericPrompt<T>): Promise<
T extends true ? Exclude<BooleanSelectValues, 'KEEP_CURRENT'> : 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, 'KEEP_CURRENT'>
: BooleanSelectValues;
}

interface PercentInputPrompt<T extends boolean> extends GenericPrompt<T> {
toRay?: boolean;
}
Expand Down Expand Up @@ -180,6 +140,7 @@ export async function eModesSelect<T extends boolean>({message, pool}: EModeSele
.filter((e) => e != 'NONE')
.map((eMode) => ({value: eMode})),
],
required: true,
});
return values.map((mode) => translateEModeToEModeLib(mode, pool));
} else {
Expand Down
44 changes: 44 additions & 0 deletions generator/prompts/boolPrompt.ts
Original file line number Diff line number Diff line change
@@ -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<T extends boolean>({
message,
required,
defaultValue,
}: GenericPrompt<T> & {
defaultValue?: T extends true
? Exclude<BooleanSelectValues, 'KEEP_CURRENT'>
: BooleanSelectValues;
}): Promise<T extends true ? Exclude<BooleanSelectValues, 'KEEP_CURRENT'> : BooleanSelectValues> {
const choices = [
...(required ? [] : [{value: ENGINE_FLAGS.KEEP_CURRENT}]),
{value: ENGINE_FLAGS.ENABLED},
{value: ENGINE_FLAGS.DISABLED},
];
return select<
T extends true ? Exclude<BooleanSelectValues, 'KEEP_CURRENT'> : 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');
}
}

0 comments on commit 780b9c8

Please sign in to comment.