Skip to content

Commit

Permalink
Add mercury contract wrappers (#10492)
Browse files Browse the repository at this point in the history
* Add mercury contract wrappers

* Update contracts

* Add VerifyBulk
  • Loading branch information
lukaszcl authored Sep 11, 2023
1 parent f2bcbbf commit dc3272d
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
43 changes: 43 additions & 0 deletions integration-tests/contracts/contract_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package contracts

import (
"errors"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

Expand All @@ -12,6 +13,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_forwarder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy"
)

// ContractLoader is an interface for abstracting the contract loading methods across network implementations
Expand All @@ -24,6 +27,10 @@ type ContractLoader interface {
LoadFunctionsCoordinator(addr string) (FunctionsCoordinator, error)
LoadFunctionsRouter(addr string) (FunctionsRouter, error)
LoadFunctionsLoadTestClient(addr string) (FunctionsLoadTestClient, error)

// Mercury
LoadMercuryVerifier(addr string) (MercuryVerifier, error)
LoadMercuryVerifierProxy(addr string) (MercuryVerifierProxy, error)
}

// NewContractLoader returns an instance of a contract Loader based on the client type
Expand Down Expand Up @@ -189,3 +196,39 @@ func (e *EthereumContractLoader) LoadAuthorizedForwarder(address common.Address)
authorizedForwarder: instance.(*authorized_forwarder.AuthorizedForwarder),
}, err
}

// LoadMercuryVerifier returns Verifier contract deployed on given address
func (e *EthereumContractLoader) LoadMercuryVerifier(addr string) (MercuryVerifier, error) {
instance, err := e.client.LoadContract("Mercury Verifier", common.HexToAddress(addr), func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
return verifier.NewVerifier(address, backend)
})
if err != nil {
return nil, err
}
return &EthereumMercuryVerifier{
client: e.client,
instance: instance.(*verifier.Verifier),
address: common.HexToAddress(addr),
}, err
}

// LoadMercuryVerifierProxy returns VerifierProxy contract deployed on given address
func (e *EthereumContractLoader) LoadMercuryVerifierProxy(addr string) (MercuryVerifierProxy, error) {
instance, err := e.client.LoadContract("Mercury Verifier Proxy", common.HexToAddress(addr), func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
return verifier_proxy.NewVerifierProxy(address, backend)
})
if err != nil {
return nil, err
}
return &EthereumMercuryVerifierProxy{
client: e.client,
instance: instance.(*verifier_proxy.VerifierProxy),
address: common.HexToAddress(addr),
}, err
}
11 changes: 11 additions & 0 deletions integration-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,14 @@ type FunctionsLoadTestClient interface {
SendRequest(times uint32, source string, encryptedSecretsReferences []byte, args []string, subscriptionId uint64, jobId [32]byte) error
SendRequestWithDONHostedSecrets(times uint32, source string, slotID uint8, slotVersion uint64, args []string, subscriptionId uint64, donID [32]byte) error
}

type MercuryVerifier interface {
Address() string
Verify(signedReport []byte, sender common.Address) error
}

type MercuryVerifierProxy interface {
Address() string
Verify(signedReport []byte, value *big.Int) (*types.Transaction, error)
VerifyBulk(signedReports [][]byte, value *big.Int) (*types.Transaction, error)
}
64 changes: 64 additions & 0 deletions integration-tests/contracts/ethereum_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/oracle_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/test_api_consumer_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy"
)

// EthereumOracle oracle for "directrequest" job tests
Expand Down Expand Up @@ -2244,3 +2246,65 @@ func (e *EthereumFunctionsLoadTestClient) SendRequestWithDONHostedSecrets(times
}
return e.client.ProcessTransaction(tx)
}

type EthereumMercuryVerifier struct {
address common.Address
client blockchain.EVMClient
instance *verifier.Verifier
}

func (e *EthereumMercuryVerifier) Address() string {
return e.address.Hex()
}

func (e *EthereumMercuryVerifier) Verify(signedReport []byte, sender common.Address) error {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if err != nil {
return err
}
tx, err := e.instance.Verify(opts, signedReport, sender)
if err != nil {
return err
}
return e.client.ProcessTransaction(tx)
}

type EthereumMercuryVerifierProxy struct {
address common.Address
client blockchain.EVMClient
instance *verifier_proxy.VerifierProxy
}

func (e *EthereumMercuryVerifierProxy) Address() string {
return e.address.Hex()
}

func (e *EthereumMercuryVerifierProxy) Verify(signedReport []byte, value *big.Int) (*types.Transaction, error) {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if value != nil {
opts.Value = value
}
if err != nil {
return nil, err
}
tx, err := e.instance.Verify(opts, signedReport)
if err != nil {
return nil, err
}
return tx, e.client.ProcessTransaction(tx)
}

func (e *EthereumMercuryVerifierProxy) VerifyBulk(signedReports [][]byte, value *big.Int) (*types.Transaction, error) {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if value != nil {
opts.Value = value
}
if err != nil {
return nil, err
}
tx, err := e.instance.VerifyBulk(opts, signedReports)
if err != nil {
return nil, err
}
return tx, e.client.ProcessTransaction(tx)
}

0 comments on commit dc3272d

Please sign in to comment.