Skip to content

Commit

Permalink
feat: add abis to js exports (#229)
Browse files Browse the repository at this point in the history
* feat: add abis to js exports

* fix: add generated comment
  • Loading branch information
sakulstra authored Aug 31, 2023
1 parent cc08bf9 commit bff33fc
Show file tree
Hide file tree
Showing 7 changed files with 1,254 additions and 2 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ jobs:
check-proposals:
name: Check if library is up to date
runs-on: ubuntu-latest
env:
FOUNDRY_PROFILE: ci
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- uses: actions/setup-node@v3
with:
Expand Down
39 changes: 39 additions & 0 deletions scripts/generator/abis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import util from 'node:util';
import {exec} from 'node:child_process';
import {existsSync, mkdirSync, rmSync, writeFileSync} from 'node:fs';
import {prefixWithGeneratedWarning} from './utils';

const awaitableExec = util.promisify(exec);

const INTERFACES = ['IAaveGovernanceV2', 'ICollector', 'AggregatorInterface'];

export async function generateABIs() {
if (existsSync('./src/ts/abis')) {
rmSync('./src/ts/abis', {recursive: true});
}
mkdirSync('./src/ts/abis');
const jsExports = await Promise.all(
INTERFACES.map(async (INTERFACE) => {
const {stdout, stderr} = await awaitableExec(`forge inspect ${INTERFACE} abi`);
if (stderr) {
throw new Error(`Failed to generate abi for ${INTERFACE}`);
}
const varName = `${INTERFACE}_ABI`;
writeFileSync(
`./src/ts/abis/${INTERFACE}.ts`,
prefixWithGeneratedWarning(
`export const ${varName} = ${JSON.stringify(
JSON.parse(stdout.trim()),
null,
2,
)} as const;`,
),
);
return `export {${varName}} from './abis/${INTERFACE}';`;
}),
);
return {
solidity: [],
js: jsExports,
};
}
4 changes: 4 additions & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {governanceConfigArbitrum} from './configs/governance/arbitrum';
import {governanceConfigAvalanche, governanceConfigFuji} from './configs/governance/avalanche';
import {governanceConfigOptimism} from './configs/governance/optimism';
import {governanceConfigMumbai, governanceConfigPolygon} from './configs/governance/polygon';
import {generateABIs} from './generator/abis';

async function main() {
// cleanup ts artifacts
Expand Down Expand Up @@ -101,13 +102,16 @@ async function main() {

const smImports = generateSafetyModule();

const abis = await generateABIs();

const imports = [
governanceNames,
v2LibraryNames,
v3LibraryNames,
miscImports,
govImports,
smImports,
abis,
].flat();

const jsExports = imports.map((f) => f.js).flat();
Expand Down
3 changes: 3 additions & 0 deletions src/ts/AaveAddressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ export {AaveV3HarmonyAssets} from './AaveV3HarmonyAssets';
export * as AaveMisc from './AaveMisc';
export * as AaveGovernanceV2 from './AaveGovernanceV2';
export * as AaveSafetyModule from './AaveSafetyModule';
export {IAaveGovernanceV2_ABI} from './abis/IAaveGovernanceV2';
export {ICollector_ABI} from './abis/ICollector';
export {AggregatorInterface_ABI} from './abis/AggregatorInterface';
130 changes: 130 additions & 0 deletions src/ts/abis/AggregatorInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// AUTOGENERATED - MANUALLY CHANGES WILL BE REVERTED BY THE GENERATOR
export const AggregatorInterface_ABI = [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'int256',
name: 'current',
type: 'int256',
},
{
indexed: true,
internalType: 'uint256',
name: 'roundId',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'updatedAt',
type: 'uint256',
},
],
name: 'AnswerUpdated',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'uint256',
name: 'roundId',
type: 'uint256',
},
{
indexed: true,
internalType: 'address',
name: 'startedBy',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'startedAt',
type: 'uint256',
},
],
name: 'NewRound',
type: 'event',
},
{
inputs: [
{
internalType: 'uint256',
name: 'roundId',
type: 'uint256',
},
],
name: 'getAnswer',
outputs: [
{
internalType: 'int256',
name: '',
type: 'int256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: 'roundId',
type: 'uint256',
},
],
name: 'getTimestamp',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'latestAnswer',
outputs: [
{
internalType: 'int256',
name: '',
type: 'int256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'latestRound',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'latestTimestamp',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
] as const;
Loading

0 comments on commit bff33fc

Please sign in to comment.