Skip to content

Commit

Permalink
fix: add chainId to js sm export (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Jan 25, 2024
1 parent 376d312 commit 988ec45
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 160 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
},
"homepage": "https://github.com/bgd-labs/aave-address-book#readme",
"devDependencies": {
"@bgd-labs/js-utils": "^1.1.0",
"@bgd-labs/js-utils": "^1.1.1",
"@types/node": "^20.10.5",
"esbuild-plugin-file-path-extensions": "^2.0.0",
"prettier": "^3.0.3",
"prettier-plugin-solidity": "^1.1.3",
"tsup": "^8.0.1",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"viem": "^2.1.1"
"viem": "^2.5.0"
}
}
8 changes: 4 additions & 4 deletions scripts/generator/governanceV3Generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {writeFileSync} from 'fs';
import {Hex, PublicClient, getContract, Address} from 'viem';
import {Hex, getContract, Address, Client} from 'viem';
import {Addresses, GovernanceConfig} from '../configs/types';
import {
generateJsConstants,
Expand All @@ -20,7 +20,7 @@ type ExecutorsV3 = {
};

async function fetchV3ExecutorAddresses(
client: PublicClient,
client: Client,
payloadsController: Hex,
): Promise<ExecutorsV3> {
const payloadsControllerContract = getContract({
Expand All @@ -39,7 +39,7 @@ async function fetchV3ExecutorAddresses(
};
}

async function getVotingStrategyAndWarehouse(votingMachine: Address, client: PublicClient) {
async function getVotingStrategyAndWarehouse(votingMachine: Address, client: Client) {
const votingMachineContract = getContract({
address: votingMachine,
abi: IVotingMachineWithProofs_ABI,
Expand All @@ -59,7 +59,7 @@ async function getVotingStrategyAndWarehouse(votingMachine: Address, client: Pub
};
}

function getGovernancePowerStrategy(governance: Address, client: PublicClient) {
function getGovernancePowerStrategy(governance: Address, client: Client) {
if (!governance) throw new Error('trying to fetch power strategy from address 0');

const governanceContract = getContract({
Expand Down
6 changes: 3 additions & 3 deletions scripts/generator/protocolV2Generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Hex, PublicClient, getContract} from 'viem';
import {Hex, Client, getContract} from 'viem';
import {AddressInfo, PoolConfig, ReserveData} from '../configs/types';
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {appendFileSync, writeFileSync} from 'fs';
Expand Down Expand Up @@ -34,7 +34,7 @@ export interface PoolV2Addresses {
}

async function getAdditionalTokenInfo(
client: PublicClient,
client: Client,
pool: Hex,
reservesData: PoolV2Addresses['reservesData'],
): Promise<{
Expand Down Expand Up @@ -75,7 +75,7 @@ async function getAdditionalTokenInfo(
}

export async function getPoolV2Addresses(pool: PoolConfig): Promise<PoolV2Addresses> {
const client = CHAIN_ID_CLIENT_MAP[pool.chainId] as PublicClient;
const client = CHAIN_ID_CLIENT_MAP[pool.chainId];
const addressProviderContract = getContract({
address: pool.POOL_ADDRESSES_PROVIDER,
abi: ADDRESS_PROVIDER_V2_ABI,
Expand Down
10 changes: 5 additions & 5 deletions scripts/generator/protocolV3Generator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Hex, PublicClient, getContract, zeroAddress} from 'viem';
import {Hex, Client, getContract, zeroAddress} from 'viem';
import {AddressInfo, Addresses, PoolConfig, ReserveData} from '../configs/types';
import {ADDRESS_PROVIDER_V3_ABI} from '../abi/address_provider_v3_abi';
import {REWARDS_CONTROLLER_ABI} from '../abi/rewardsController_v3_abi';
import {STATIC_A_TOKEN_FACTORY_ABI} from '../abi/static_a_token_factory_abi';
import {A_TOKEN_V3_ABI} from '../abi/aToken_v3_abi';
import {VARIABLE_DEBT_TOKEN_ABI} from '../abi/variableDebtToken_v3_abi';
import {STABLE_DEBT_TOKEN_ABI} from '../abi/stableDebtToken_v3_abi';
import {CHAIN_ID_CLIENT_MAP, ChainId} from '@bgd-labs/js-utils';
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {appendFileSync, writeFileSync} from 'fs';
import {
addressOrZero,
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface PoolV3Addresses {
}

async function getAdditionalTokenInfo(
client: PublicClient,
client: Client,
pool: PoolConfig,
reservesData: PoolV3Addresses['reservesData'],
): Promise<{
Expand Down Expand Up @@ -115,7 +115,7 @@ async function getAdditionalTokenInfo(
export async function getPoolV3Addresses(
pool: PoolConfig,
): Promise<PoolV3Addresses & {eModes: Map<number, string>}> {
const client: PublicClient = CHAIN_ID_CLIENT_MAP[pool.chainId];
const client = CHAIN_ID_CLIENT_MAP[pool.chainId];
const addressProviderContract = getContract({
address: pool.POOL_ADDRESSES_PROVIDER,
abi: ADDRESS_PROVIDER_V3_ABI,
Expand Down Expand Up @@ -231,7 +231,7 @@ export async function getPoolV3Addresses(
}
}

function generateEmodes(chainId: ChainId, eModes: Map<number, string>, libraryName: string) {
function generateEmodes(chainId: number, eModes: Map<number, string>, libraryName: string) {
const sorted = Array.from(eModes).sort(([keyA], [keyB]) => keyA - keyB);
const formatted = sorted.reduce((acc, [value, label]) => {
acc[`${label ? label.toUpperCase().replace('-', '_').replace(' ', '_') : 'NONE'}`] = {
Expand Down
5 changes: 4 additions & 1 deletion scripts/generator/safetyModuleGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export function generateSafetyModule() {
fs.writeFileSync(
`./src/ts/AaveSafetyModule.ts`,
prefixWithGeneratedWarning(
generateJsConstants({chainId: ChainId.mainnet, addresses: SAFETY_MODULE}).join('\n'),
generateJsConstants({
chainId: ChainId.mainnet,
addresses: {...SAFETY_MODULE, CHAIN_ID: {value: ChainId.mainnet, type: 'uint256'}},
}).join('\n'),
),
);

Expand Down
25 changes: 10 additions & 15 deletions scripts/generator/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Hex, PublicClient, getAddress, zeroAddress} from 'viem';
import {Client, Hex, getAddress, zeroAddress} from 'viem';
import {AddressInfo, Addresses} from '../configs/types';
import {CHAIN_ID_CLIENT_MAP, ChainId} from '@bgd-labs/js-utils';
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {getStorageAt} from 'viem/actions';

function getExplorerLink(chainId: ChainId, address: Hex) {
function getExplorerLink(chainId: number, address: Hex) {
const client = CHAIN_ID_CLIENT_MAP[chainId];
return `${client.chain?.blockExplorers?.default.url}/address/${getAddress(address)}`;
}
Expand All @@ -25,7 +26,7 @@ export function wrapIntoSolidityLibrary(code: string[], libraryName: string) {
}

export function addressInfoToSolidityLibraryConstant(
chainId: ChainId,
chainId: number,
key: string,
entry: AddressInfo,
) {
Expand All @@ -52,15 +53,15 @@ export function generateSolidityConstants({
chainId,
addresses,
}: {
chainId: ChainId;
chainId: number;
addresses: Addresses;
}) {
return Object.keys(addresses).map((key) =>
addressInfoToSolidityLibraryConstant(chainId, key, addresses[key]),
);
}

export function addressToJsConstant(chainId: ChainId, key: string, entry: AddressInfo) {
export function addressToJsConstant(chainId: number, key: string, entry: AddressInfo) {
if (typeof entry === 'object') {
if (entry.type === 'uint256') {
return `export const ${key} = ${entry.value};\n`;
Expand All @@ -75,13 +76,7 @@ export function addressToJsConstant(chainId: ChainId, key: string, entry: Addres
return `// ${blockExplorerLinkComment}\nexport const ${key} = '${getAddress(entry)}';\n`;
}

export function generateJsConstants({
chainId,
addresses,
}: {
chainId: ChainId;
addresses: Addresses;
}) {
export function generateJsConstants({chainId, addresses}: {chainId: number; addresses: Addresses}) {
return Object.keys(addresses).map((key) => addressToJsConstant(chainId, key, addresses[key]));
}

Expand All @@ -100,8 +95,8 @@ export const bytes32toAddress = (bytes32: Hex) => {
return getAddress(`0x${bytes32.slice(26)}`);
};

export const getImplementationStorageSlot = async (provider: PublicClient, address: Hex) => {
return (await provider.getStorageAt({
export const getImplementationStorageSlot = async (client: Client, address: Hex) => {
return (await getStorageAt(client, {
address,
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc',
})) as Hex;
Expand Down
Loading

0 comments on commit 988ec45

Please sign in to comment.