Skip to content

Commit

Permalink
trying out
Browse files Browse the repository at this point in the history
  • Loading branch information
yashnevatia committed Dec 8, 2024
1 parent 29f644f commit 2b48bdf
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 38 deletions.
66 changes: 47 additions & 19 deletions core/gethwrappers/abigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"go/ast"
"go/format"
"go/parser"
"go/printer"
"go/token"
"log"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -582,33 +587,34 @@ 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}}
// return address, ethTx, contractReturn, err
// }`
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)
}

Expand All @@ -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 {

Check failure on line 658 in core/gethwrappers/abigen.go

View workflow job for this annotation

GitHub Actions / lint

func `addZKSyncBlock` is unused (unused)
for i, stmt := range x.Body.List {
Expand Down
62 changes: 43 additions & 19 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2b48bdf

Please sign in to comment.