Skip to content

Commit

Permalink
feat: gov v3-abis (#268)
Browse files Browse the repository at this point in the history
* feat: gov v3-abis

* fix: fix ci
  • Loading branch information
sakulstra authored Oct 18, 2023
1 parent 4fc7dd7 commit 452f760
Show file tree
Hide file tree
Showing 11 changed files with 844 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: yarn install --frozen-lockfile

- name: Generate library
run: yarn start
run: yarn generate:addresses

- name: Create Pull Request
uses: peter-evans/create-pull-request@712add83f26c1e359c046a6ca3dd677fb7017626
Expand Down
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ ffi = false
optimizer = true
optimizer_runs = 1000000
verbosity = 1

[rpc_endpoints]
mainnet = "${RPC_MAINNET}"

[etherscan]
mainnet={key="${ETHERSCAN_API_KEY_MAINNET}",chainId=1}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"sideEffects": false,
"scripts": {
"prettier": "prettier --write 'src/**/*.{sol,ts}'",
"generate:abis": "tsx scripts/generateABIs.ts",
"generate:addresses": "tsx scripts/generateAddresses.ts",
"start": "yarn generate:abis && yarn generate:addresses && npm run prettier",
"generate:abis": "tsx scripts/generateABIs.ts && npm run prettier",
"generate:addresses": "tsx scripts/generateAddresses.ts && npm run prettier",
"start": "tsx scripts/generateABIs.ts &&tsx scripts/generateAddresses.ts && npm run prettier",
"build": "tsup",
"ci:publish": "npm run build && npm publish --access=public"
},
Expand Down
22 changes: 22 additions & 0 deletions scripts/configs/abis.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {ChainId} from '../generator/chains';
import {governanceConfigMainnet} from './governance/ethereum';

export const ABI_INTERFACES = [
'IAaveGovernanceV2',
'ICollector',
Expand All @@ -20,3 +23,22 @@ export const ABI_INTERFACES = [
'IRescuable',
'IOwnable',
];

export const DOWNLOAD_ABI_INTERFACES = [
{
address: governanceConfigMainnet.ADDRESSES.PC_DATA_HELPER,
name: 'IPayloadsControllerDataHelper',
},
{
address: governanceConfigMainnet.ADDRESSES.GOV_DATA_HELPER,
name: 'IGovernanceDataHelper',
},
{
address: governanceConfigMainnet.ADDRESSES.META_DELEGATE_HELPER,
name: 'IMetaDelegateHelper',
},
{
address: governanceConfigMainnet.ADDRESSES.VM_DATA_HELPER,
name: 'IVotingMachineDataHelper',
},
];
15 changes: 14 additions & 1 deletion scripts/generateABIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import util from 'node:util';
import {exec} from 'node:child_process';
import {existsSync, mkdirSync, rmSync, writeFileSync} from 'node:fs';
import {prefixWithGeneratedWarning} from './generator/utils';
import {ABI_INTERFACES} from './configs/abis';
import {ABI_INTERFACES, DOWNLOAD_ABI_INTERFACES} from './configs/abis';

const awaitableExec = util.promisify(exec);

Expand All @@ -24,6 +24,19 @@ export async function generateABIs() {
),
);
}
for (const INTERFACE of DOWNLOAD_ABI_INTERFACES) {
const {stdout, stderr} = await awaitableExec(`cast interface -j ${INTERFACE.address}`);
if (stderr) {
throw new Error(`Failed to generate abi for ${INTERFACE.name} from ${INTERFACE.address}`);
}
const varName = `${INTERFACE.name}_ABI`;
writeFileSync(
`./src/ts/abis/${INTERFACE.name}.ts`,
prefixWithGeneratedWarning(
`export const ${varName} = ${JSON.stringify(JSON.parse(stdout.trim()), null, 2)} as const;`,
),
);
}
}

generateABIs();
6 changes: 5 additions & 1 deletion scripts/generator/abis.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {ABI_INTERFACES} from '../configs/abis';
import {ABI_INTERFACES, DOWNLOAD_ABI_INTERFACES} from '../configs/abis';

export function generateABIImports() {
const jsExports: string[] = [];
for (const INTERFACE of ABI_INTERFACES) {
const varName = `${INTERFACE}_ABI`;
jsExports.push(`export {${varName}} from './abis/${INTERFACE}';`);
}
for (const INTERFACE of DOWNLOAD_ABI_INTERFACES) {
const varName = `${INTERFACE.name}_ABI`;
jsExports.push(`export {${varName}} from './abis/${INTERFACE.name}';`);
}
return {
solidity: [],
js: jsExports,
Expand Down
4 changes: 4 additions & 0 deletions src/ts/AaveAddressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ export {ICrossChainController_ABI} from './abis/ICrossChainController';
export {IWithGuardian_ABI} from './abis/IWithGuardian';
export {IRescuable_ABI} from './abis/IRescuable';
export {IOwnable_ABI} from './abis/IOwnable';
export {IPayloadsControllerDataHelper_ABI} from './abis/IPayloadsControllerDataHelper';
export {IGovernanceDataHelper_ABI} from './abis/IGovernanceDataHelper';
export {IMetaDelegateHelper_ABI} from './abis/IMetaDelegateHelper';
export {IVotingMachineDataHelper_ABI} from './abis/IVotingMachineDataHelper';
Loading

0 comments on commit 452f760

Please sign in to comment.