wevm/wagmi

bug: foundry plugin multiple addresses referencing the same ABI

Open

#4396 aperta il 10 nov 2024

Vedi su GitHub
 (2 commenti) (2 reazioni) (0 assegnatari)TypeScript (1399 fork)user submission
Good First Issue

Metriche repository

Star
 (6711 star)
Metriche merge PR
 (Merge medio 2g 13h) (15 PR mergiate in 30 g)

Descrizione

Check existing issues

Describe the bug

At Zora, we use the foundry plugin and love it. However, if you have multiple addresses that need to share the same ABI (e.g. different ERC20 tokens) it doesn't work.

If I am reading in a deployment file and writing the addresses like in this example: https://github.com/ourzora/zora-721-contracts/blob/main/wagmi.config.ts

Example extending that:

type ContractNames =
  // ...
  | 'ERC20';

type Address = `0x${string}`;

const contractFilesToInclude: ContractNames[] = [
  // ...
  'ERC20'
];

  for (const addressesFile of addressesFiles) {
    const jsonAddress = JSON.parse(
      readFileSync(`./addresses/${addressesFile}`, 'utf-8')
    ) as {
      // ... 
      WETH: Address;
      DAI: Address;
    };

    addAddress(
      'ZoraNFTCreatorV1',
      chainId,
      jsonAddress.ZORA_NFT_CREATOR_PROXY
    );
    addAddress('ERC20', chainId, jsonAddress.DAI);
    addAddress('ERC20', chainId, jsonAddress.WETH);

only the daiConfig / daiAddress gets created, but not the WETH config.

Link to Minimal Reproducible Example

https://gist.github.com/0x6080/126272e246be09b24274acd3aae55bd5

Steps To Reproduce

If I am reading in a deployment file and writing the addresses like in this example: https://github.com/ourzora/zora-721-contracts/blob/main/wagmi.config.ts

Example extending that:

type ContractNames =
  // ...
  | 'ERC20';

type Address = `0x${string}`;

const contractFilesToInclude: ContractNames[] = [
  // ...
  'ERC20'
];

  for (const addressesFile of addressesFiles) {
    const jsonAddress = JSON.parse(
      readFileSync(`./addresses/${addressesFile}`, 'utf-8')
    ) as {
      // ... 
      WETH: Address;
      DAI: Address;
    };

    // ... 
    addAddress('ERC20', chainId, jsonAddress.DAI);
    addAddress('ERC20', chainId, jsonAddress.WETH);

only the daiConfig / daiAddress gets created:

/**
 *
 */
export const daiAddress = {
  31337: '0xF0794f5a1318CAbf8270AFeeA33cB2b7543d1839',
} as const

/**
 *
 */
export const daiConfig = {
  address: daiAddress,
  abi: erc20Abi,
} as const

but not the WETH config.

What Wagmi package(s) are you using?

@wagmi/cli

Wagmi Package(s) Version(s)

2.12.24

Viem Version

2.21.35

TypeScript Version

20

Anything else?

Ideal behavior would be for both of them to reference the same abi, for example:

export const wethConfig = {
  address: wethAddress,
  abi: erc20Abi,
} as const

Guida contributor