@@ -3,20 +3,21 @@ import {bytes32ToAddress} from '../utils/storageSlots';
33import { diffCode , downloadContract } from './code-diff' ;
44import { RawStorage , SlotDiff } from './snapshot-types' ;
55import { isKnownAddress } from '../govv3/utils/checkAddress' ;
6- import { Address , getContract , zeroHash } from 'viem' ;
6+ import { Address , getContract , isAddress , toBytes , zeroHash } from 'viem' ;
77import { getClient } from '@bgd-labs/rpc-env' ;
88import { IPool_ABI } from '@bgd-labs/aave-address-book/abis' ;
99
1010export function diffSlot ( chainId : number , address : Address , slot : SlotDiff ) {
11+ const fromAddress = isAddress ( slot . previousValue )
12+ ? slot . previousValue
13+ : bytes32ToAddress ( slot . previousValue ) ;
14+ const toAddress = isAddress ( slot . newValue ) ? slot . newValue : bytes32ToAddress ( slot . newValue ) ;
1115 // pure new deployments cannot be diffed, we just download the code in that case
1216 if ( slot . previousValue == zeroHash ) {
13- const toAddress = bytes32ToAddress ( slot . newValue ) ;
1417 const to = downloadContract ( chainId , toAddress ) ;
1518 mkdirSync ( './diffs' , { recursive : true } ) ;
1619 writeFileSync ( `./diffs/${ chainId } _${ address } _${ toAddress } .diff` , readFileSync ( to ) , { } ) ;
1720 } else {
18- const fromAddress = bytes32ToAddress ( slot . previousValue ) ;
19- const toAddress = bytes32ToAddress ( slot . newValue ) ;
2021 const from = downloadContract ( chainId , fromAddress ) ;
2122 const to = downloadContract ( chainId , toAddress ) ;
2223 const result = diffCode ( from , to ) ;
@@ -50,34 +51,41 @@ export async function diffRawStorage(chainId: number, raw: RawStorage) {
5051 // ... we might want to fetch the owner in that case
5152 }
5253
53- // Diff code logic libraries
54- if ( contractName && contractName [ contractName . length - 1 ] === 'POOL' ) {
55- const oldPool = getContract ( {
56- client : getClient ( chainId , { } ) ,
57- abi : IPool_ABI ,
58- address : bytes32ToAddress ( raw [ contract ] . stateDiff [ erc1967ImplSlot ] . previousValue ) ,
59- } ) ;
60- const newPool = getContract ( {
61- client : getClient ( chainId , { } ) ,
62- abi : IPool_ABI ,
63- address : bytes32ToAddress ( raw [ contract ] . stateDiff [ erc1967ImplSlot ] . previousValue ) ,
64- } ) ;
65- const addresses = await Promise . all ( [
66- oldPool . read . getSupplyLogic ( ) ,
67- newPool . read . getSupplyLogic ( ) ,
68- oldPool . read . getBorrowLogic ( ) ,
69- newPool . read . getBorrowLogic ( ) ,
70- oldPool . read . getLiquidationLogic ( ) ,
71- newPool . read . getLiquidationLogic ( ) ,
72- oldPool . read . getPoolLogic ( ) ,
73- newPool . read . getPoolLogic ( ) ,
74- oldPool . read . getFlashLoanLogic ( ) ,
75- newPool . read . getFlashLoanLogic ( ) ,
76- oldPool . read . getEModeLogic ( ) ,
77- newPool . read . getEModeLogic ( ) ,
78- ] ) ;
79- for ( let i = 0 ; i < addresses . length ; i = i + 2 ) {
80- diffSlot ( chainId , contract , { previousValue : addresses [ i ] , newValue : addresses [ i + 1 ] } ) ;
54+ if ( contractName ) {
55+ const path = contractName [ 0 ] . split ( '.' ) ;
56+ // Diff code logic libraries
57+ if ( path [ path . length - 1 ] === 'POOL' ) {
58+ const oldPool = getContract ( {
59+ client : getClient ( chainId , { } ) ,
60+ abi : IPool_ABI ,
61+ address : bytes32ToAddress ( raw [ contract ] . stateDiff [ erc1967ImplSlot ] . previousValue ) ,
62+ } ) ;
63+ const newPool = getContract ( {
64+ client : getClient ( chainId , { } ) ,
65+ abi : IPool_ABI ,
66+ address : bytes32ToAddress ( raw [ contract ] . stateDiff [ erc1967ImplSlot ] . previousValue ) ,
67+ } ) ;
68+ const addresses = await Promise . all ( [
69+ oldPool . read . getSupplyLogic ( ) ,
70+ newPool . read . getSupplyLogic ( ) ,
71+ oldPool . read . getBorrowLogic ( ) ,
72+ newPool . read . getBorrowLogic ( ) ,
73+ oldPool . read . getLiquidationLogic ( ) ,
74+ newPool . read . getLiquidationLogic ( ) ,
75+ oldPool . read . getPoolLogic ( ) ,
76+ newPool . read . getPoolLogic ( ) ,
77+ oldPool . read . getFlashLoanLogic ( ) ,
78+ newPool . read . getFlashLoanLogic ( ) ,
79+ oldPool . read . getEModeLogic ( ) ,
80+ newPool . read . getEModeLogic ( ) ,
81+ ] ) ;
82+ console . log ( 'addr' , addresses ) ;
83+ for ( let i = 0 ; i < addresses . length ; i = i + 2 ) {
84+ diffSlot ( chainId , contract , {
85+ previousValue : addresses [ i ] ,
86+ newValue : addresses [ i + 1 ] ,
87+ } ) ;
88+ }
8189 }
8290 }
8391 }
0 commit comments