IPcl.pclProxy

pclProxy(address proxy) external view returns (PclProxyEntry memory)

PCL 프리컴파일의 deployPclProxy로 배포된 프록시의 레지스트리 엔트리를 반환합니다. 현재 엔트리는 프록시 변형을 식별하는 kind 필드 하나만 포함하며, V1에서는 PclProxyKind.Transparent만 등록됩니다. 조회한 주소가 등록된 PCL 래핑 프록시가 아니면 반환된 struct의 모든 필드가 0이며, kindPclProxyKind.Unspecified(enum 값 0)로 디코드됩니다.

파라미터

이름 타입 필수 설명
proxy address PCL 프록시 레지스트리에서 조회할 프록시 컨트랙트 주소입니다.

반환값

타입: PclProxyEntry

PclProxyKind kind 필드 하나를 가진 PclProxyEntry struct를 반환합니다. PclProxyKindUnspecified(0)과 Transparent(1) 값을 갖는 enum입니다. 등록되지 않은 주소는 kindUnspecified인 엔트리를 반환합니다.

예제

주소가 등록된 PCL 프록시인지 확인 (viem)

프록시 주소에 대한 레지스트리 엔트리를 조회합니다. Unspecified kind(0)는 해당 주소가 PCL에 등록된 프록시가 아니라는 의미입니다.

import { createPublicClient, http } from "viem";

const PCL = "0x1000000000000000000000000000000000000005" as const;

const pclAbi = [{
  name: "pclProxy",
  type: "function",
  stateMutability: "view",
  inputs: [{ name: "proxy", type: "address" }],
  outputs: [{
    type: "tuple",
    components: [
      { name: "kind", type: "uint8" },
    ],
  }],
}] as const;

const publicClient = createPublicClient({ transport: http("https://rpc-testnet.maroo.io") });

// Replace with the deployed proxy address before production use.
const proxyAddress = "0x1111111111111111111111111111111111111111" as const;

const entry = await publicClient.readContract({
  address: PCL,
  abi: pclAbi,
  functionName: "pclProxy",
  args: [proxyAddress],
});

// PclProxyKind: 0 = Unspecified (not registered), 1 = Transparent
if (entry.kind === 0) {
  console.log("not a PCL-wrapped proxy");
} else {
  console.log("kind =", entry.kind);
}

Solidity — PCL 프록시 등록 여부로 코드 경로 분기

컨트랙트는 pclProxy를 사용하여 호출을 라우팅하기 전에 대상 주소가 체인에서 인식하는 PCL 래핑 프록시인지 확인할 수 있습니다.

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import { IPcl, PclProxyEntry, PclProxyKind } from "@maroo-chain/contracts/precompiles/pcl/IPcl.sol";

contract PolicyAwareCaller {
    IPcl constant PCL = IPcl(0x1000000000000000000000000000000000000005);

    error NotAPclProxy(address target);

    function requirePclProxy(address target) external view {
        PclProxyEntry memory entry = PCL.pclProxy(target);
        if (entry.kind == PclProxyKind.Unspecified) {
            revert NotAPclProxy(target);
        }
    }
}
ESC
검색어를 입력하세요