Skip to content

Commit

Permalink
feat: add new e-mode category via the generator
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlymite committed Oct 25, 2023
1 parent 50339c5 commit c7a3381
Showing 1 changed file with 48 additions and 22 deletions.
70 changes: 48 additions & 22 deletions generator/features/eModesUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
import {CodeArtifact, FEATURE, FeatureModule, PoolIdentifier} from '../types';
import {addressInput, eModesSelect, percentInput, stringInput} from '../prompts';
import {EModeCategoryUpdate} from './types';
import {confirm} from '@inquirer/prompts';

async function fetchEmodeCategoryUpdate(isNewCategory: boolean, eModeCategory?: string): Promise<EModeCategoryUpdate> {
return {
eModeCategory: eModeCategory ?? await stringInput({message: 'eModeCategory'}),
ltv: await percentInput({
message: 'ltv',
disableKeepCurrent: isNewCategory ? true : false
}),
liqThreshold: await percentInput({
message: 'liqThreshold',
disableKeepCurrent: isNewCategory ? true : false
}),
liqBonus: await percentInput({
message: 'liqBonus',
disableKeepCurrent: isNewCategory ? true : false
}),
priceSource: await addressInput({
message: 'Price Source',
disableKeepCurrent: isNewCategory ? true : false
}),
label: await stringInput({
message: 'label',
disableKeepCurrent: isNewCategory ? true : false
}),
};
}

async function subCli(pool: PoolIdentifier) {
console.log(`Fetching information for EModes on ${pool}`);
const eModeCategories = await eModesSelect({
message: 'Select the eModes you want to amend',
pool,
});
const answers: EmodeUpdates = [];
for (const eModeCategory of eModeCategories) {
console.log(`collecting info for ${eModeCategory}`);
answers.push({
eModeCategory,
ltv: await percentInput({
message: 'ltv',
}),
liqThreshold: await percentInput({
message: 'liqThreshold',
}),
liqBonus: await percentInput({
message: 'liqBonus',
}),
priceSource: await addressInput({
message: 'Price Source',
}),
label: await stringInput({message: 'label'}),

const shouldAddNewCategory = await confirm({message: 'Do you wish to add a new emode category?', default: false});
if (shouldAddNewCategory) {
let more: boolean = true;
while (more) {
answers.push(await fetchEmodeCategoryUpdate(true));
more = await confirm({message: 'Do you want to add another emode category?', default: false});
}
}

const shouldAmendCategory = await confirm({message: 'Do you wish to amend existing emode category?', default: false});
if (shouldAmendCategory) {
const eModeCategories = await eModesSelect({
message: 'Select the eModes you want to amend',
pool,
});

for (const eModeCategory of eModeCategories) {
console.log(`collecting info for ${eModeCategory}`);
answers.push(await fetchEmodeCategoryUpdate(false, eModeCategory));
}
}

return answers;
}

Expand Down

0 comments on commit c7a3381

Please sign in to comment.