( parameters: EncodeDeployDataParameters<abi>, )
| 47 | | ErrorType |
| 48 | |
| 49 | export function encodeDeployData<const abi extends Abi | readonly unknown[]>( |
| 50 | parameters: EncodeDeployDataParameters<abi>, |
| 51 | ): EncodeDeployDataReturnType { |
| 52 | const { abi, args, bytecode, deploymentType, salt } = |
| 53 | parameters as EncodeDeployDataParameters |
| 54 | |
| 55 | if (!args || args.length === 0) { |
| 56 | const { functionName, argsContractDeployer } = getDeploymentDetails( |
| 57 | deploymentType, |
| 58 | salt ?? zeroHash, |
| 59 | toHex(hashBytecode(bytecode)), |
| 60 | '0x', |
| 61 | ) |
| 62 | return encodeFunctionData({ |
| 63 | abi: contractDeployerAbi, |
| 64 | functionName, |
| 65 | args: argsContractDeployer, |
| 66 | }) |
| 67 | } |
| 68 | |
| 69 | const description = abi.find((x) => 'type' in x && x.type === 'constructor') |
| 70 | if (!description) throw new AbiConstructorNotFoundError({ docsPath }) |
| 71 | if (!('inputs' in description)) |
| 72 | throw new AbiConstructorParamsNotFoundError({ docsPath }) |
| 73 | if (!description.inputs || description.inputs.length === 0) |
| 74 | throw new AbiConstructorParamsNotFoundError({ docsPath }) |
| 75 | |
| 76 | const data = encodeAbiParameters(description.inputs, args) |
| 77 | const { functionName, argsContractDeployer } = getDeploymentDetails( |
| 78 | deploymentType, |
| 79 | salt ?? zeroHash, |
| 80 | toHex(hashBytecode(bytecode)), |
| 81 | data, |
| 82 | ) |
| 83 | |
| 84 | return encodeFunctionData({ |
| 85 | abi: contractDeployerAbi, |
| 86 | functionName, |
| 87 | args: argsContractDeployer, |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | function getDeploymentDetails( |
| 92 | deploymentType: ContractDeploymentType, |
no test coverage detected