Skip to content

Commit

Permalink
fix: allow addition of new pool
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Mar 13, 2024
1 parent c748d63 commit 18c4471
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 109 deletions.
107 changes: 58 additions & 49 deletions generator/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@ const FEATURE_MODULES_V3 = [
PLACEHOLDER_MODULE,
];

async function generateDeterministicPoolCache(pool: PoolIdentifier): Promise<PoolCache> {
const chain = getPoolChain(pool);
const client = CHAIN_ID_CLIENT_MAP[CHAIN_TO_CHAIN_ID[chain]];
return {blockNumber: Number(await getBlockNumber(client))};
}

async function fetchPoolOptions(pool: PoolIdentifier) {
poolConfigs[pool] = {
configs: {},
artifacts: [],
cache: await generateDeterministicPoolCache(pool),
};

const v2 = isV2Pool(pool);
const features = await checkbox({
message: `What do you want to do on ${pool}?`,
choices: v2
? FEATURE_MODULES_V2.map((m) => ({value: m.value, name: m.description}))
: FEATURE_MODULES_V3.map((m) => ({value: m.value, name: m.description})),
});
for (const feature of features) {
const module = v2
? FEATURE_MODULES_V2.find((m) => m.value === feature)!
: FEATURE_MODULES_V3.find((m) => m.value === feature)!;
poolConfigs[pool]!.configs[feature] = await module.cli({
options,
pool,
cache: poolConfigs[pool]!.cache,
});
poolConfigs[pool]!.artifacts.push(
module.build({
options,
pool,
cfg: poolConfigs[pool]!.configs[feature],
cache: poolConfigs[pool]!.cache,
})
);
}
}

if (options.configFile) {
const {config: cfgFile}: {config: ConfigFile} = await import(
path.join(process.cwd(), options.configFile)
Expand All @@ -83,19 +123,23 @@ if (options.configFile) {
poolConfigs = cfgFile.poolOptions as any;
for (const pool of options.pools) {
const v2 = isV2Pool(pool);
poolConfigs[pool]!.artifacts = [];
for (const feature of Object.keys(poolConfigs[pool]!.configs)) {
const module = v2
? FEATURE_MODULES_V2.find((m) => m.value === feature)!
: FEATURE_MODULES_V3.find((m) => m.value === feature)!;
poolConfigs[pool]!.artifacts.push(
module.build({
options,
pool,
cfg: poolConfigs[pool]!.configs[feature],
cache: poolConfigs[pool]!.cache,
})
);
if (poolConfigs[pool]) {
poolConfigs[pool]!.artifacts = [];
for (const feature of Object.keys(poolConfigs[pool]!.configs)) {
const module = v2
? FEATURE_MODULES_V2.find((m) => m.value === feature)!
: FEATURE_MODULES_V3.find((m) => m.value === feature)!;
poolConfigs[pool]!.artifacts.push(
module.build({
options,
pool,
cfg: poolConfigs[pool]!.configs[feature],
cache: poolConfigs[pool]!.cache,
})
);
}
} else {
await fetchPoolOptions(pool);
}
}
} else {
Expand Down Expand Up @@ -150,43 +194,8 @@ if (options.configFile) {
});
}

async function generateDeterministicPoolCache(pool: PoolIdentifier): Promise<PoolCache> {
const chain = getPoolChain(pool);
const client = CHAIN_ID_CLIENT_MAP[CHAIN_TO_CHAIN_ID[chain]];
return {blockNumber: Number(await getBlockNumber(client))};
}

for (const pool of options.pools) {
poolConfigs[pool] = {
configs: {},
artifacts: [],
cache: await generateDeterministicPoolCache(pool),
};
const v2 = isV2Pool(pool);
const features = await checkbox({
message: `What do you want to do on ${pool}?`,
choices: v2
? FEATURE_MODULES_V2.map((m) => ({value: m.value, name: m.description}))
: FEATURE_MODULES_V3.map((m) => ({value: m.value, name: m.description})),
});
for (const feature of features) {
const module = v2
? FEATURE_MODULES_V2.find((m) => m.value === feature)!
: FEATURE_MODULES_V3.find((m) => m.value === feature)!;
poolConfigs[pool]!.configs[feature] = await module.cli({
options,
pool,
cache: poolConfigs[pool]!.cache,
});
poolConfigs[pool]!.artifacts.push(
module.build({
options,
pool,
cfg: poolConfigs[pool]!.configs[feature],
cache: poolConfigs[pool]!.cache,
})
);
}
await fetchPoolOptions(pool);
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"@types/node": "^20.11.10",
"prettier": "2.8.7",
"prettier-plugin-solidity": "1.1.3",
"vitest": "^1.2.2"
"vitest": "^1.3.1"
},
"dependencies": {
"@bgd-labs/aave-address-book": "^2.23.0",
"@bgd-labs/aave-address-book": "^2.24.0",
"@bgd-labs/aave-cli": "0.8.0",
"@bgd-labs/js-utils": "^1.3.0",
"@inquirer/prompts": "^3.3.0",
Expand All @@ -41,7 +41,7 @@
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"tsx": "^4.7.0",
"viem": "^2.6.1"
"viem": "^2.8.5"
},
"lint-staged": {
"*": "prettier --ignore-unknown --write"
Expand Down
118 changes: 61 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
dependencies:
svgo "^3.2.0"

"@bgd-labs/aave-address-book@^2.23.0":
version "2.23.0"
resolved "https://registry.yarnpkg.com/@bgd-labs/aave-address-book/-/aave-address-book-2.23.0.tgz#d5d58bf0768391ad92e4c9d737308684dbc2abc9"
integrity sha512-T+ZPq74gmBpySaXaMcgy0vLuZP5jR8BFoZyiu/RWUsHJo9QrKSv39dFqyGdUTx3rgKVQatcqB9RpSKWu+4aA/Q==
"@bgd-labs/aave-address-book@^2.24.0":
version "2.24.0"
resolved "https://registry.yarnpkg.com/@bgd-labs/aave-address-book/-/aave-address-book-2.24.0.tgz#da9814cdfc9daecb83d1995f3587f4c82a66269b"
integrity sha512-JYeiHWRv0B1vC4BNIN+e9qZyGGDV8v6jZPHlsG7AkCWTBZb7PZBqLJhauFn+/CAnLYr6uK8SWvl47mgCDIgI1g==
dependencies:
svgo "^3.2.0"

Expand Down Expand Up @@ -803,44 +803,44 @@
resolved "https://registry.npmjs.org/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz"
integrity sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==

"@vitest/expect@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-1.2.2.tgz#39ea22e849bbf404b7e5272786551aa99e2663d0"
integrity sha512-3jpcdPAD7LwHUUiT2pZTj2U82I2Tcgg2oVPvKxhn6mDI2On6tfvPQTjAI4628GUGDZrCm4Zna9iQHm5cEexOAg==
"@vitest/expect@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-1.3.1.tgz#d4c14b89c43a25fd400a6b941f51ba27fe0cb918"
integrity sha512-xofQFwIzfdmLLlHa6ag0dPV8YsnKOCP1KdAeVVh34vSjN2dcUiXYCD9htu/9eM7t8Xln4v03U9HLxLpPlsXdZw==
dependencies:
"@vitest/spy" "1.2.2"
"@vitest/utils" "1.2.2"
"@vitest/spy" "1.3.1"
"@vitest/utils" "1.3.1"
chai "^4.3.10"

"@vitest/runner@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-1.2.2.tgz#8b060a56ecf8b3d607b044d79f5f50d3cd9fee2f"
integrity sha512-JctG7QZ4LSDXr5CsUweFgcpEvrcxOV1Gft7uHrvkQ+fsAVylmWQvnaAr/HDp3LAH1fztGMQZugIheTWjaGzYIg==
"@vitest/runner@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-1.3.1.tgz#e7f96cdf74842934782bfd310eef4b8695bbfa30"
integrity sha512-5FzF9c3jG/z5bgCnjr8j9LNq/9OxV2uEBAITOXfoe3rdZJTdO7jzThth7FXv/6b+kdY65tpRQB7WaKhNZwX+Kg==
dependencies:
"@vitest/utils" "1.2.2"
"@vitest/utils" "1.3.1"
p-limit "^5.0.0"
pathe "^1.1.1"

"@vitest/snapshot@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-1.2.2.tgz#f56fd575569774968f3eeba9382a166c26201042"
integrity sha512-SmGY4saEw1+bwE1th6S/cZmPxz/Q4JWsl7LvbQIky2tKE35US4gd0Mjzqfr84/4OD0tikGWaWdMja/nWL5NIPA==
"@vitest/snapshot@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-1.3.1.tgz#193a5d7febf6ec5d22b3f8c5a093f9e4322e7a88"
integrity sha512-EF++BZbt6RZmOlE3SuTPu/NfwBF6q4ABS37HHXzs2LUVPBLx2QoY/K0fKpRChSo8eLiuxcbCVfqKgx/dplCDuQ==
dependencies:
magic-string "^0.30.5"
pathe "^1.1.1"
pretty-format "^29.7.0"

"@vitest/spy@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-1.2.2.tgz#8fc2aeccb96cecbbdd192c643729bd5f97a01c86"
integrity sha512-k9Gcahssw8d7X3pSLq3e3XEu/0L78mUkCjivUqCQeXJm9clfXR/Td8+AP+VC1O6fKPIDLcHDTAmBOINVuv6+7g==
"@vitest/spy@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-1.3.1.tgz#814245d46d011b99edd1c7528f5725c64e85a88b"
integrity sha512-xAcW+S099ylC9VLU7eZfdT9myV67Nor9w9zhf0mGCYJSO+zM2839tOeROTdikOi/8Qeusffvxb/MyBSOja1Uig==
dependencies:
tinyspy "^2.2.0"

"@vitest/utils@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-1.2.2.tgz#94b5a1bd8745ac28cf220a99a8719efea1bcfc83"
integrity sha512-WKITBHLsBHlpjnDQahr+XK6RE7MiAsgrIkr0pGhQ9ygoxBfUeG0lUG5iLlzqjmKSlBv3+j5EGsriBzh+C3Tq9g==
"@vitest/utils@1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-1.3.1.tgz#7b05838654557544f694a372de767fcc9594d61a"
integrity sha512-d3Waie/299qqRyHTm2DjADeTaNdNSVsnwHPWrs20JMpjh6eiVq7ggggweO8rc4arhf6rRkWuHKwvxGvejUXZZQ==
dependencies:
diff-sequences "^29.6.3"
estree-walker "^3.0.3"
Expand Down Expand Up @@ -1685,6 +1685,11 @@ js-tokens@^4.0.0:
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-tokens@^8.0.2:
version "8.0.3"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-8.0.3.tgz#1c407ec905643603b38b6be6977300406ec48775"
integrity sha512-UfJMcSJc+SEXEl9lH/VLHSZbThQyLpw1vLO1Lb+j4RWDvG3N2f7yj3PVQA3cmkTBNldJ9eFnM+xEXxHIXrYiJw==

js-yaml@^3.13.1:
version "3.14.1"
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz"
Expand Down Expand Up @@ -2481,12 +2486,12 @@ strip-indent@^3.0.0:
dependencies:
min-indent "^1.0.0"

strip-literal@^1.3.0:
version "1.3.0"
resolved "https://registry.npmjs.org/strip-literal/-/strip-literal-1.3.0.tgz"
integrity sha512-PugKzOsyXpArk0yWmUwqOZecSO0GH0bPoctLcqNDH9J04pVW3lflYE0ujElBGTloevcxF5MofAOZ7C5l2b+wLg==
strip-literal@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-literal/-/strip-literal-2.0.0.tgz#5d063580933e4e03ebb669b12db64d2200687527"
integrity sha512-f9vHgsCWBq2ugHAkGMiiYY+AYG0D/cbloKKg0nhaaaSNsujdGIpVXCNsrJpCKr5M0f4aI31mr13UjY6GAuXCKA==
dependencies:
acorn "^8.10.0"
js-tokens "^8.0.2"

supports-color@^5.3.0:
version "5.5.0"
Expand Down Expand Up @@ -2661,10 +2666,10 @@ varint@^6.0.0:
resolved "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz"
integrity sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==

viem@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.6.1.tgz#aaab145746e019fdb0a838e32c19bad69d6b2a15"
integrity sha512-565cKS2fQ8XU9sfQo5NGAZXdKwPFjof4nO3NUyElVHKqKw9l5/y2iDDMEubvxm09rBlzibJ+Sw/mI4jnnkQE4g==
viem@^2.7.1:
version "2.7.6"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.7.6.tgz#2ada30ece1469367b606137983e5655cf66d721e"
integrity sha512-43TF0VYcTeNef9dax1/BhqlRLXpAo6HAiQ68hrJ8XRhDOou73nHZEjeFl8Eai4UFFodKhu+PbRUFzuuoixOUfg==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
Expand All @@ -2675,10 +2680,10 @@ viem@^2.6.1:
isows "1.0.3"
ws "8.13.0"

viem@^2.7.1:
version "2.7.6"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.7.6.tgz#2ada30ece1469367b606137983e5655cf66d721e"
integrity sha512-43TF0VYcTeNef9dax1/BhqlRLXpAo6HAiQ68hrJ8XRhDOou73nHZEjeFl8Eai4UFFodKhu+PbRUFzuuoixOUfg==
viem@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.8.5.tgz#c0120e7f228fbb5be760c625bb2637c7cfa1b8df"
integrity sha512-EAmZ/jP7Ycmu72zRrB+N/fINEXMVBaLLsUaHwu5LoIjAzmE/f/33RV9AlhUA6RNZ5kujomylSytIyDakzQYXCQ==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
Expand All @@ -2689,10 +2694,10 @@ viem@^2.7.1:
isows "1.0.3"
ws "8.13.0"

vite-node@1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-1.2.2.tgz#f6d329b06f9032130ae6eac1dc773f3663903c25"
integrity sha512-1as4rDTgVWJO3n1uHmUYqq7nsFgINQ9u+mRcXpjeOMJUmviqNKjcZB7UfRZrlM7MjYXMKpuWp5oGkjaFLnjawg==
vite-node@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-1.3.1.tgz#a93f7372212f5d5df38e945046b945ac3f4855d2"
integrity sha512-azbRrqRxlWTJEVbzInZCTchx0X69M/XPTCz4H+TLvlTcR/xH/3hkRqhOakT41fMJCMzXTu4UvegkZiEoJAWvng==
dependencies:
cac "^6.7.14"
debug "^4.3.4"
Expand All @@ -2711,18 +2716,17 @@ vite@^5.0.0:
optionalDependencies:
fsevents "~2.3.3"

vitest@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-1.2.2.tgz#9e29ad2a74a5df553c30c5798c57a062d58ce299"
integrity sha512-d5Ouvrnms3GD9USIK36KG8OZ5bEvKEkITFtnGv56HFaSlbItJuYr7hv2Lkn903+AvRAgSixiamozUVfORUekjw==
dependencies:
"@vitest/expect" "1.2.2"
"@vitest/runner" "1.2.2"
"@vitest/snapshot" "1.2.2"
"@vitest/spy" "1.2.2"
"@vitest/utils" "1.2.2"
vitest@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-1.3.1.tgz#2d7e9861f030d88a4669392a4aecb40569d90937"
integrity sha512-/1QJqXs8YbCrfv/GPQ05wAZf2eakUPLPa18vkJAKE7RXOKfVHqMZZ1WlTjiwl6Gcn65M5vpNUB6EFLnEdRdEXQ==
dependencies:
"@vitest/expect" "1.3.1"
"@vitest/runner" "1.3.1"
"@vitest/snapshot" "1.3.1"
"@vitest/spy" "1.3.1"
"@vitest/utils" "1.3.1"
acorn-walk "^8.3.2"
cac "^6.7.14"
chai "^4.3.10"
debug "^4.3.4"
execa "^8.0.1"
Expand All @@ -2731,11 +2735,11 @@ vitest@^1.2.2:
pathe "^1.1.1"
picocolors "^1.0.0"
std-env "^3.5.0"
strip-literal "^1.3.0"
strip-literal "^2.0.0"
tinybench "^2.5.1"
tinypool "^0.8.2"
vite "^5.0.0"
vite-node "1.2.2"
vite-node "1.3.1"
why-is-node-running "^2.2.2"

webidl-conversions@^3.0.0:
Expand Down

0 comments on commit 18c4471

Please sign in to comment.