diff --git a/core/gethwrappers/abigen.go b/core/gethwrappers/abigen.go index a023af0e574..aaa09eac517 100644 --- a/core/gethwrappers/abigen.go +++ b/core/gethwrappers/abigen.go @@ -6,7 +6,9 @@ import ( "go/ast" "go/format" "go/parser" + "go/printer" "go/token" + "log" "os" "os/exec" "path/filepath" @@ -539,11 +541,14 @@ func updateDeployMethod(contractName string, fset *token.FileSet, fileNode *ast. // only add this import if Deploy method found astutil.AddImport(fset, fileNode, "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated") + fmt.Println("here") + // Extract the parameters from the existing function x paramList := getConstructorParams(x.Type.Params.List) - // get the `if zksync()` block - zkSyncBlock := getZKSyncBlock(contractName, paramList) - + paramListWithTypes := getConstructorParamsWithTypes(x.Type.Params.List) + fmt.Println("paramListWithTypes: ", paramListWithTypes) + zkSyncBlock := getZKSyncBlock(contractName, paramList, paramListWithTypes) + fmt.Println("zkSyncBlock: ", zkSyncBlock) node, err := parser.ParseFile(token.NewFileSet(), "", zkSyncBlock, parser.SkipObjectResolution) if err != nil { return false @@ -582,25 +587,25 @@ func parseFuncDecl(funcCode string) (*ast.FuncDecl, error) { } var zkcode = ` -package main -func Deploy%sZK(auth *bind.TransactOpts, backend bind.ContractBackend, params string) (common.Address, *generated.Transaction, *%s, error) { - parsed, err := %sMetaData.GetAbi() - if err != nil { - return common.Address{}, nil, nil, err - } - if parsed == nil { - return common.Address{}, nil, nil, errors.New("GetABI returned nil") - } - address, ethTx, contract, err := generated.DeployContract(auth, parsed, common.FromHex(%sZKBin), backend, params) - if err != nil { - return common.Address{}, nil, nil, err + package main + func Deploy%sZK(auth *bind.TransactOpts, backend bind.ContractBackend, %constructorParams) (common.Address, *generated.Transaction, *%s, error) { + parsed, err := %sMetaData.GetAbi() + if err != nil { + return common.Address{}, nil, nil, err + } + if parsed == nil { + return common.Address{}, nil, nil, errors.New("GetABI returned nil") + } + address, ethTx, contract, err := generated.DeployContract(auth, parsed, common.FromHex(%sZKBin), backend, %deployParams) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, ethTx, &%s{address: address, abi: *parsed, %sCaller: %sCaller{contract: contract}, %sTransactor: %sTransactor{contract: contract}, %sFilterer: %sFilterer{contract: contract}}, nil } - return address, ethTx, &%s{address: address, abi: *parsed, %sCaller: %sCaller{contract: contract}, %sTransactor: %sTransactor{contract: contract}, %sFilterer: %sFilterer{contract: contract}}, nil -} ` // get the `if zksync()` block -func getZKSyncBlock(contractName, paramList string) string { +func getZKSyncBlock(contractName, paramList, paramListWithTypes string) string { // zkSyncBlock := `if generated_zks.IsZKSync(backend) { // address, ethTx, contractBind, _ := generated_zks.DeployContract(auth, parsed, common.FromHex(%sZKBin), backend, %params) // contractReturn := &%s{address: address, abi: *parsed, %sCaller: %sCaller{contract: contractBind}, %sTransactor: %sTransactor{contract: contractBind},%sFilterer: %sFilterer{contract: contractBind}} @@ -608,7 +613,8 @@ func getZKSyncBlock(contractName, paramList string) string { // }` zkSyncBlock := zkcode zkSyncBlock = strings.ReplaceAll(zkSyncBlock, "%s", contractName) - zkSyncBlock = strings.ReplaceAll(zkSyncBlock, "%params", paramList) + zkSyncBlock = strings.ReplaceAll(zkSyncBlock, "%constructorParams", paramListWithTypes) + zkSyncBlock = strings.ReplaceAll(zkSyncBlock, "%deployParams", paramList) return strings.ReplaceAll(zkSyncBlock, "%s", contractName) } @@ -626,6 +632,28 @@ func getConstructorParams(contstructorParams []*ast.Field) string { return paramList } +func getConstructorParamsWithTypes(constructorParams []*ast.Field) string { + params := []string{} + for i, param := range constructorParams { + if i > 1 { // Skip auth and backend + for _, name := range param.Names { + paramWithType := fmt.Sprintf("%s %s", name.Name, exprToString(param.Type)) + params = append(params, paramWithType) + } + } + } + return strings.Join(params, ", ") +} + +func exprToString(expr ast.Expr) string { + var buf bytes.Buffer + err := printer.Fprint(&buf, token.NewFileSet(), expr) + if err != nil { + log.Fatalf("Failed to convert AST expression to string: %v", err) + } + return buf.String() +} + // insert the `if zksync()` block func addZKSyncBlock(x ast.FuncDecl, zkSyncBlock string) ast.FuncDecl { for i, stmt := range x.Body.List { diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index bc3dc01ad1b..e9f182efc9e 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -210,28 +210,28 @@ func deployChainContracts( if chainState.Router == nil { return fmt.Errorf("router not found for chain %s, deploy the prerequisites first", chain.String()) } + var err2 error + var dtx deployTx if chainState.Receiver == nil { _, err := deployment.DeployContract(e.Logger, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] { var receiverAddr common.Address var receiver *maybe_revert_message_receiver.MaybeRevertMessageReceiver - var err2 error - var tx deployTx if generated.IsZKSync(chain.Client) { - receiverAddr, tx, receiver, err2 = maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver( + receiverAddr, dtx, receiver, err2 = maybe_revert_message_receiver.DeployMaybeRevertMessageReceiverZK( chain.DeployerKey, chain.Client, false, ) } else { - receiverAddr, tx, receiver, err2 = maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver( + receiverAddr, dtx, receiver, err2 = maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver( chain.DeployerKey, chain.Client, false, ) } return deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver]{ - receiverAddr, receiver, tx.Hash(), deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), err2, + receiverAddr, receiver, dtx.Hash(), deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), err2, } }) if err != nil { @@ -246,15 +246,28 @@ func deployChainContracts( // TODO: Correctly configure RMN remote. rmnRemote, err := deployment.DeployContract(e.Logger, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*rmn_remote.RMNRemote] { - rmnRemoteAddr, tx, rmnRemote, err2 := rmn_remote.DeployRMNRemote( - chain.DeployerKey, - chain.Client, - chain.Selector, - // Indicates no legacy RMN contract - common.HexToAddress("0x0"), - ) + var rmnRemoteAddr common.Address + var rmnRemote *rmn_remote.RMNRemote + + if generated.IsZKSync(chain.Client) { + rmnRemoteAddr, dtx, rmnRemote, err2 = rmn_remote.DeployRMNRemote( + chain.DeployerKey, + chain.Client, + chain.Selector, + // Indicates no legacy RMN contract + common.HexToAddress("0x0"), + ) + } else { + rmnRemoteAddr, dtx, rmnRemote, err2 = rmn_remote.DeployRMNRemote( + chain.DeployerKey, + chain.Client, + chain.Selector, + // Indicates no legacy RMN contract + common.HexToAddress("0x0"), + ) + } return deployment.ContractDeploy[*rmn_remote.RMNRemote]{ - rmnRemoteAddr, rmnRemote, tx, deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev), err2, + rmnRemoteAddr, rmnRemote, dtx.Hash(), deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev), err2, } }) if err != nil { @@ -291,13 +304,24 @@ func deployChainContracts( // we deploy a new rmnproxy contract to test RMNRemote rmnProxy, err := deployment.DeployContract(e.Logger, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract] { - rmnProxyAddr, tx, rmnProxy, err2 := rmn_proxy_contract.DeployRMNProxyContract( - chain.DeployerKey, - chain.Client, - rmnRemoteContract.Address(), - ) + var rmnProxyAddr common.Address + var rmnProxy *rmn_proxy_contract.RMNProxyContract + if generated.IsZKSync(chain.Client) { + rmnProxyAddr, dtx, rmnProxy, err2 = rmn_proxy_contract.DeployRMNProxyContractZK( + chain.DeployerKey, + chain.Client, + rmnRemoteContract.Address(), + ) + } else { + rmnProxyAddr, dtx, rmnProxy, err2 = rmn_proxy_contract.DeployRMNProxyContract( + chain.DeployerKey, + chain.Client, + rmnRemoteContract.Address(), + ) + } + return deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract]{ - rmnProxyAddr, rmnProxy, tx, deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_6_0_dev), err2, + rmnProxyAddr, rmnProxy, dtx.Hash(), deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_6_0_dev), err2, } }) if err != nil {