Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make room for protocol versions. #122

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
258 changes: 129 additions & 129 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lint:solidity": "solhint 'src/helpers/contracts/**/*.sol'",
"lint:typescript": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0",
"prepack": "yarn build",
"test": "yarn build && hardhat test ./tasks/**/test/*.ts",
"test": "yarn build && hardhat test v*/tasks/**/test/*.ts",
"ci:prepare-config": "ts-node ci/prepare-config.ts"
},
"devDependencies": {
Expand Down
93 changes: 64 additions & 29 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import { getContractDeploymentTransactionHash, saveContractDeploymentTransaction
import { getTaskActionIds } from './actionId';
import { getArtifactFromContractOutput } from './artifact';

const TASKS_DIRECTORY = path.resolve(__dirname, '../tasks');
const DEPRECATED_DIRECTORY = path.join(TASKS_DIRECTORY, 'deprecated');
const SCRIPTS_DIRECTORY = path.join(TASKS_DIRECTORY, 'scripts');
// Maps to ../v2 and ../v3.
const VERSION_ROOTS = ['v2', 'v3'].map((version) => path.resolve(__dirname, `../${version}`));

// Maps to v2/tasks, v3/tasks, etc.
const getTasksDir = (versionRoot: string) => path.resolve(versionRoot, 'tasks');
const getDeprecatedDir = (versionRoot: string) => path.resolve(versionRoot, 'deprecated');
const getScriptsDir = (versionRoot: string) => path.resolve(versionRoot, 'scripts');

export enum TaskMode {
LIVE, // Deploys and saves outputs
Expand Down Expand Up @@ -208,25 +212,36 @@ export default class Task {
dir(): string {
if (!this.id) throw Error('Please provide a task deployment ID to run');

// The task might be deprecated, so it may not exist in the main directory. We first look there, but don't require
// that the directory exists.
const __dir = (versionRoot: string): string | undefined => {
// The task might be deprecated, so it may not exist in the main directory. We first look there, but don't require
// that the directory exists.

const nonDeprecatedDir = this._dirAt(TASKS_DIRECTORY, this.id, false);
if (this._existsDir(nonDeprecatedDir)) {
return nonDeprecatedDir;
}
const nonDeprecatedDir = this._dirAt(getTasksDir(versionRoot), this.id, false);
if (this._existsDir(nonDeprecatedDir)) {
return nonDeprecatedDir;
}

const deprecatedDir = this._dirAt(DEPRECATED_DIRECTORY, this.id, false);
if (this._existsDir(deprecatedDir)) {
return deprecatedDir;
}
const deprecatedDir = this._dirAt(getDeprecatedDir(versionRoot), this.id, false);
if (this._existsDir(deprecatedDir)) {
return deprecatedDir;
}

const scriptsDir = this._dirAt(getScriptsDir(versionRoot), this.id, false);
if (this._existsDir(scriptsDir)) {
return scriptsDir;
}

return undefined;
};

const scriptsDir = this._dirAt(SCRIPTS_DIRECTORY, this.id, false);
if (this._existsDir(scriptsDir)) {
return scriptsDir;
for (const versionRoot of VERSION_ROOTS) {
const dirFound = __dir(versionRoot);
if (dirFound !== undefined) {
return dirFound;
}
}

throw Error(`Could not find a directory at ${nonDeprecatedDir}, ${deprecatedDir} or ${scriptsDir}`);
throw Error(`Could not find a directory at ${VERSION_ROOTS}`);
}

buildInfo(fileName: string): BuildInfo {
Expand Down Expand Up @@ -319,12 +334,23 @@ export default class Task {

getStatus(): TaskStatus {
const taskDirectory = this.dir();
if (taskDirectory === path.join(TASKS_DIRECTORY, this.id)) {
return TaskStatus.ACTIVE;
} else if (taskDirectory === path.join(DEPRECATED_DIRECTORY, this.id)) {
return TaskStatus.DEPRECATED;
} else if (taskDirectory === path.join(SCRIPTS_DIRECTORY, this.id)) {
return TaskStatus.SCRIPT;
const __taskStatus = (versionRoot: string): TaskStatus | undefined => {
if (taskDirectory === path.join(getTasksDir(versionRoot), this.id)) {
return TaskStatus.ACTIVE;
} else if (taskDirectory === path.join(getDeprecatedDir(versionRoot), this.id)) {
return TaskStatus.DEPRECATED;
} else if (taskDirectory === path.join(getScriptsDir(versionRoot), this.id)) {
return TaskStatus.SCRIPT;
} else {
return undefined;
}
};

for (const versionRoot of VERSION_ROOTS) {
const taskStatus = __taskStatus(versionRoot);
if (taskStatus !== undefined) {
return taskStatus;
}
}

throw new Error('Unknown task status');
Expand Down Expand Up @@ -452,11 +478,20 @@ export default class Task {
* Return all directories inside the top 3 fixed task directories in a flat, sorted array.
*/
static getAllTaskIds(): string[] {
// Some operating systems may insert hidden files that should not be listed, so we just look for directories when
// reading the file system.
return [TASKS_DIRECTORY, DEPRECATED_DIRECTORY, SCRIPTS_DIRECTORY]
.map((dir) => fs.readdirSync(dir).filter((fileName) => fs.lstatSync(path.resolve(dir, fileName)).isDirectory()))
.flat()
.sort();
const __versionTaskIds = (versionRoot: string): string[] => {
// Some operating systems may insert hidden files that should not be listed, so we just look for directories when
// reading the file system.
return [getTasksDir(versionRoot), getDeprecatedDir(versionRoot), getScriptsDir(versionRoot)]
.map((dir) => fs.readdirSync(dir).filter((fileName) => fs.lstatSync(path.resolve(dir, fileName)).isDirectory()))
.flat()
.sort();
};

let taskIds: string[] = [];
for (const versionRoot of VERSION_ROOTS) {
taskIds = taskIds.concat(__versionTaskIds(versionRoot));
}

return taskIds;
}
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": ["tasks/**/test", "tasks/**/index.ts", "tasks/**/input.ts", "index.ts", "src", "addresses/**/*.json", "tasks/**/artifact/*.json", "tasks/**/output/*.json"],
"exclude": ["tasks/**/output/test.json"],
"include": ["*/tasks/**/test", "*/tasks/**/index.ts", "*/tasks/**/input.ts", "index.ts", "src", "addresses/**/*.json", "*/tasks/**/artifact/*.json", "*/tasks/**/output/*.json"],
"exclude": ["*/tasks/**/output/test.json"],
"files": ["./hardhat.config.ts"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> ⚠️ **DEPRECATED: do not use** ⚠️
>
> This factory and associated Pools have been deprecated due to incorrect calculation of protocol fees when the global protocol swap fee percentage is non-zero. They have been [temporarily replaced with a version that addresses this](../../20211202-no-protocol-fee-lbp).
> This factory and associated Pools have been deprecated due to incorrect calculation of protocol fees when the global protocol swap fee percentage is non-zero. They have been [temporarily replaced with a version that addresses this](../../tasks/20211202-no-protocol-fee-lbp).

Deployment of the `LiquidityBootstrappingPoolFactory`, for Liquidity Bootstrapping Pools of up to 4 tokens.

Expand Down
Loading