Skip to content

Commit

Permalink
(fix) Types
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Jan 29, 2025
1 parent 6567936 commit 8c61c92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/execution/address/AddressReadContractAsProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ContentFrame from "../../components/ContentFrame";
import { addressURL } from "../../url.ts";

const AddressReadContractAsProxy: FC = () => {
const { address, outerMatch, outerWhatsabiMatch } =
const { address } =
useOutletContext() as AddressOutletContext;
const { config, provider } = useContext(RuntimeContext);
const proxyAttributes = useERC1967ProxyAttributes(provider, address);
Expand All @@ -29,7 +29,7 @@ const AddressReadContractAsProxy: FC = () => {
<p className="py-6" > Reading ERC-1967 proxy
<NavLink className="rounded-lg bg-link-blue/10 px-2 py-1 text-xs text-link-blue hover:bg-link-blue/100 hover:text-white" to={addressURL(address)}>{address}</NavLink>
whose implementation is at
<NavLink className="rounded-lg bg-link-blue/10 px-2 py-1 text-xs text-link-blue hover:bg-link-blue/100 hover:text-white" to={addressURL(proxyAttributes?.delegate)}>{proxyAttributes?.delegate}</NavLink>.
<NavLink className="rounded-lg bg-link-blue/10 px-2 py-1 text-xs text-link-blue hover:bg-link-blue/100 hover:text-white" to={addressURL(proxyAttributes!.delegate)}>{proxyAttributes?.delegate}</NavLink>.
</p>
</div>
<ReadContract checksummedAddress={address} match={match ?? whatsabiMatch} />
Expand Down
29 changes: 16 additions & 13 deletions src/useERC1967.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ import {
TransactionResponse,
ZeroAddress,
getAddress,
BigNumber
BigNumberish,
} from "ethers";
import { Fetcher } from "swr";
import useSWRImmutable from "swr/immutable";
import erc20 from "../abi/erc20.json";

type Address = string;

const DELEGATE_STORAGE_LOCATION = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
const BEACON_STORAGE_LOCATION = "0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50";
const ADMIN_STORAGE_LOCATION = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";

export type ERC1967ProxyAttributes = {
delegate: ChecksummedAddress,
beacon: ChecksummedAddress,
admin: ChecksummedAddress
delegate: Address,
beacon: Address | undefined,
admin: Address | undefined
};

export const GetStorageQuery = (
provider: JsonRpcAPiProvider,
address: ChecksummedAddress,
provider: JsonRpcApiProvider,
address: Address,
slot: string,
) => {
return {
Expand All @@ -36,19 +37,21 @@ export const GetStorageQuery = (
};


export const useERC1967ProxyAttributes = (provider: JsonRpcProvider, address: ChecksummedAddress): Fetcher<ERC1967ProxyAttributes> | undefined => {
const { data: delegateData }= useQuery(GetStorageQuery(provider, address, DELEGATE_STORAGE_LOCATION) );
const { data: beaconData }= useQuery(GetStorageQuery(provider, address, BEACON_STORAGE_LOCATION) );
const { data: adminData }= useQuery(GetStorageQuery(provider, address, ADMIN_STORAGE_LOCATION) );

export const useERC1967ProxyAttributes = (provider: JsonRpcApiProvider, address: Address | undefined): ERC1967ProxyAttributes | undefined => {
function toAddress(s: string | undefined) : string | undefined {
if (s===undefined || s === "0x") {
return undefined;
}
const addr = getAddress("0x" + s.toLowerCase().slice(-40));
return addr;
}


if (address === undefined) {
return undefined
}
const { data: delegateData }= useQuery(GetStorageQuery(provider, address, DELEGATE_STORAGE_LOCATION) );
const { data: beaconData }= useQuery(GetStorageQuery(provider, address, BEACON_STORAGE_LOCATION) );
const { data: adminData }= useQuery(GetStorageQuery(provider, address, ADMIN_STORAGE_LOCATION) );

const delegate = toAddress(delegateData);
const beacon = toAddress(beaconData);
Expand Down

0 comments on commit 8c61c92

Please sign in to comment.