From 5c692ac2567c69c0980ccffa132a53a8f92d0b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 11 Jul 2023 17:42:53 +0900 Subject: [PATCH] Use latest upstream sdk: starknet.go --- integration-tests/common/common.go | 2 +- integration-tests/common/test_common.go | 49 ++++++---- integration-tests/go.mod | 12 ++- integration-tests/go.sum | 12 ++- monitoring/go.mod | 8 +- monitoring/go.sum | 19 +++- monitoring/pkg/monitoring/source_envelope.go | 32 ++++--- .../pkg/monitoring/source_envelope_test.go | 8 +- monitoring/pkg/monitoring/source_proxy.go | 11 ++- monitoring/pkg/monitoring/source_txresults.go | 11 ++- ops/devnet/devnet.go | 6 +- ops/go.mod | 8 +- ops/go.sum | 19 +++- relayer/go.mod | 8 +- relayer/go.sum | 19 +++- relayer/pkg/chainlink/ocr2/client.go | 94 +++++++++---------- relayer/pkg/chainlink/ocr2/client_test.go | 23 +++-- relayer/pkg/chainlink/ocr2/config_digester.go | 4 +- relayer/pkg/chainlink/ocr2/contract_reader.go | 12 ++- .../chainlink/ocr2/contract_transmitter.go | 32 +++++-- relayer/pkg/chainlink/ocr2/events.go | 70 ++++++-------- relayer/pkg/chainlink/ocr2/events_test.go | 14 +-- .../ocr2/medianreport/onchainconfig.go | 17 +--- .../pkg/chainlink/ocr2/medianreport/report.go | 57 +++++++---- .../ocr2/medianreport/report_test.go | 5 +- .../pkg/chainlink/ocr2/mocks/OCR2Reader.go | 60 ++++++------ relayer/pkg/chainlink/ocr2/types.go | 28 +++--- relayer/pkg/chainlink/ocr2/types_test.go | 13 +-- relayer/pkg/chainlink/txm/keystore.go | 4 +- .../txm/mocks/nonce_manager_client.go | 12 +-- relayer/pkg/chainlink/txm/nonce.go | 18 ++-- relayer/pkg/chainlink/txm/nonce_test.go | 14 ++- relayer/pkg/chainlink/txm/test_helpers.go | 8 +- relayer/pkg/chainlink/txm/txm.go | 44 +++++---- relayer/pkg/chainlink/txm/txm_test.go | 44 +++++---- relayer/pkg/chainlink/txm/txstore.go | 20 ++-- relayer/pkg/chainlink/txm/txstore_test.go | 29 +++--- relayer/pkg/starknet/client.go | 58 ++++++------ relayer/pkg/starknet/client_test.go | 8 +- relayer/pkg/starknet/mocks/Reader.go | 84 ++++++++--------- relayer/pkg/starknet/types.go | 8 +- relayer/pkg/starknet/utils.go | 33 +------ relayer/pkg/starknet/utils_test.go | 24 ----- 43 files changed, 577 insertions(+), 484 deletions(-) diff --git a/integration-tests/common/common.go b/integration-tests/common/common.go index 835dd0ce2..9a6000f1c 100644 --- a/integration-tests/common/common.go +++ b/integration-tests/common/common.go @@ -13,7 +13,7 @@ import ( uuid "github.com/satori/go.uuid" "gopkg.in/guregu/null.v4" - "github.com/smartcontractkit/caigo/gateway" + "github.com/NethermindEth/starknet.go/gateway" "github.com/smartcontractkit/chainlink-env/environment" "github.com/smartcontractkit/chainlink-env/pkg/alias" diff --git a/integration-tests/common/test_common.go b/integration-tests/common/test_common.go index c8815d4ce..1b0b2d2e7 100644 --- a/integration-tests/common/test_common.go +++ b/integration-tests/common/test_common.go @@ -10,8 +10,10 @@ import ( "testing" "time" - caigo "github.com/smartcontractkit/caigo" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" + caigo "github.com/NethermindEth/starknet.go" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -266,20 +268,28 @@ func (testState *Test) ValidateRounds(rounds int, isSoak bool) error { var positive bool // validate balance in aggregator + linkContractAddress, err := starknetutils.HexToFelt(testState.LinkTokenAddr) + if err != nil { + return err + } + contractAddress, err := starknetutils.HexToFelt(testState.OCRAddr) + if err != nil { + return err + } resLINK, errLINK := testState.Starknet.CallContract(ctx, starknet.CallOps{ - ContractAddress: caigotypes.StrToFelt(testState.LinkTokenAddr), - Selector: "balance_of", - Calldata: []string{testState.OCRAddr}, + ContractAddress: linkContractAddress, + Selector: starknettypes.GetSelectorFromNameFelt("balance_of"), + Calldata: []*felt.Felt{contractAddress}, }) - require.NoError(testState.T, errLINK, "Reader balance from LINK contract should not fail") + require.NoError(testState.T, errLINK, "Reader balance from LINK contract should not fail", "err", errLINK) resAgg, errAgg := testState.Starknet.CallContract(ctx, starknet.CallOps{ - ContractAddress: caigotypes.StrToFelt(testState.OCRAddr), - Selector: "link_available_for_payment", + ContractAddress: contractAddress, + Selector: starknettypes.GetSelectorFromNameFelt("link_available_for_payment"), }) - require.NoError(testState.T, errAgg, "Reader balance from LINK contract should not fail") - balLINK, _ := new(big.Int).SetString(resLINK[0], 0) - balAgg, _ := new(big.Int).SetString(resAgg[1], 0) - isNegative, _ := new(big.Int).SetString(resAgg[0], 0) + require.NoError(testState.T, errAgg, "link_available_for_payment should not fail", "err", errAgg) + balLINK := resLINK[0].BigInt(big.NewInt(0)) + balAgg := resAgg[1].BigInt(big.NewInt(0)) + isNegative := resAgg[0].BigInt(big.NewInt(0)) if isNegative.Sign() > 0 { balAgg = new(big.Int).Neg(balAgg) } @@ -289,8 +299,8 @@ func (testState *Test) ValidateRounds(rounds int, isSoak bool) error { for start := time.Now(); time.Since(start) < testState.Common.TestDuration; { l.Info().Msg(fmt.Sprintf("Elapsed time: %s, Round wait: %s ", time.Since(start), testState.Common.TestDuration)) - res, err := testState.OCR2Client.LatestTransmissionDetails(ctx, caigotypes.StrToFelt(testState.OCRAddr)) - require.NoError(testState.T, err, "Failed to get latest transmission details") + res, err2 := testState.OCR2Client.LatestTransmissionDetails(ctx, contractAddress) + require.NoError(testState.T, err2, "Failed to get latest transmission details") // end condition: enough rounds have occurred if !isSoak && increasing >= rounds && positive { break @@ -361,15 +371,20 @@ func (testState *Test) ValidateRounds(rounds int, isSoak bool) error { // Test proxy reading // TODO: would be good to test proxy switching underlying feeds + + proxyAddress, err := starknetutils.HexToFelt(testState.ProxyAddr) + if err != nil { + return err + } roundDataRaw, err := testState.Starknet.CallContract(ctx, starknet.CallOps{ - ContractAddress: caigotypes.StrToFelt(testState.ProxyAddr), - Selector: "latest_round_data", + ContractAddress: proxyAddress, + Selector: starknettypes.GetSelectorFromNameFelt("latest_round_data"), }) if !isSoak { require.NoError(testState.T, err, "Reading round data from proxy should not fail") assert.Equal(testState.T, len(roundDataRaw), 5, "Round data from proxy should match expected size") } - valueBig, err := starknet.HexToUnsignedBig(roundDataRaw[1]) + valueBig := roundDataRaw[1].BigInt(big.NewInt(0)) require.NoError(testState.T, err) value := valueBig.Int64() if value < 0 { diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 80e493987..c46c63bd7 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -3,9 +3,10 @@ module github.com/smartcontractkit/chainlink-starknet/integration-tests go 1.20 require ( + github.com/NethermindEth/juno v0.3.1 + github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3 github.com/rs/zerolog v1.29.1 github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-env v0.36.1-0.20230802063028-a432269a7384 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a github.com/smartcontractkit/chainlink-starknet/ops v0.0.0-20230329050701-40e3b18bb026 @@ -14,6 +15,13 @@ require ( github.com/smartcontractkit/chainlink/v2 v2.2.1-0.20230809180636-8e89b62488d7 ) +require ( + github.com/bits-and-blooms/bitset v1.7.0 // indirect + github.com/consensys/gnark-crypto v0.11.0 // indirect + github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect + github.com/test-go/testify v1.1.4 // indirect +) + require ( contrib.go.opencensus.io/exporter/stackdriver v0.13.5 // indirect cosmossdk.io/errors v1.0.0 // indirect @@ -48,7 +56,7 @@ require ( github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cockroachdb/errors v1.9.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect - github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // indirect + github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14 // indirect github.com/cockroachdb/redact v1.1.3 // indirect github.com/cometbft/cometbft v0.37.2 // indirect github.com/cometbft/cometbft-db v0.7.0 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 8d3ed4f6c..453ac0854 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -87,6 +87,10 @@ github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0 github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/NethermindEth/juno v0.3.1 h1:AW72LiAm9gqUeCVJWvepnZcTnpU4Vkl0KzPMxS+42FA= +github.com/NethermindEth/juno v0.3.1/go.mod h1:SGbTpgGaCsxhFsKOid7Ylnz//WZ8swtILk+NbHGsk/Q= +github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3 h1:SAE7oDXo82lT+arBtg6sozPMt9bNSkXY1A2TxlCGRw4= +github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3/go.mod h1:4fchLnLzJuwl1bnNUR+iBjKYN11afzJCdBcGZKIuFeU= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.5 h1:zl/OfRA6nftbBK9qTohYBJ5xvw6C/oNKizR7cZGl3cI= @@ -133,6 +137,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= +github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHfpE= github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc= @@ -193,8 +199,8 @@ github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZO github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= -github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811/go.mod h1:Nb5lgvnQ2+oGlE/EyZy4+2/CxRh9KfvCXnag1vtpxVM= +github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14 h1:4spJmU4jzTXRbaQV9yrGHBDL/nTgaebjbW4Qidtkz0w= +github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14/go.mod h1:Nb5lgvnQ2+oGlE/EyZy4+2/CxRh9KfvCXnag1vtpxVM= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= @@ -204,6 +210,8 @@ github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0 github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= +github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqqExkAtyks= +github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= diff --git a/monitoring/go.mod b/monitoring/go.mod index 0ebe72d6f..9735be612 100644 --- a/monitoring/go.mod +++ b/monitoring/go.mod @@ -3,8 +3,9 @@ module github.com/smartcontractkit/chainlink-starknet/monitoring go 1.20 require ( + github.com/NethermindEth/juno v0.3.1 + github.com/NethermindEth/starknet.go v0.4.2-0.20230804102546-d30334cf21f3 github.com/prometheus/client_golang v1.15.0 - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20230508053614-9f2fd5fd4ff1 github.com/smartcontractkit/libocr v0.0.0-20230802221916-2271752fa829 @@ -15,15 +16,18 @@ require ( require ( github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/confluentinc/confluent-kafka-go v1.9.2 // indirect + github.com/consensys/gnark-crypto v0.11.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/ethereum/go-ethereum v1.11.5 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect @@ -57,8 +61,10 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.1.1 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/stretchr/objx v0.5.0 // indirect + github.com/test-go/testify v1.1.4 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.5.0 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect go.opentelemetry.io/otel v1.16.0 // indirect diff --git a/monitoring/go.sum b/monitoring/go.sum index 7592200b9..ecfa59ecf 100644 --- a/monitoring/go.sum +++ b/monitoring/go.sum @@ -37,6 +37,10 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= +github.com/NethermindEth/juno v0.3.1 h1:AW72LiAm9gqUeCVJWvepnZcTnpU4Vkl0KzPMxS+42FA= +github.com/NethermindEth/juno v0.3.1/go.mod h1:SGbTpgGaCsxhFsKOid7Ylnz//WZ8swtILk+NbHGsk/Q= +github.com/NethermindEth/starknet.go v0.4.2-0.20230804102546-d30334cf21f3 h1:hjY72ob267YRlORRxi0kO85h2emR6EYn0BlUpM0+avY= +github.com/NethermindEth/starknet.go v0.4.2-0.20230804102546-d30334cf21f3/go.mod h1:4fchLnLzJuwl1bnNUR+iBjKYN11afzJCdBcGZKIuFeU= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/actgardner/gogen-avro/v10 v10.1.0/go.mod h1:o+ybmVjEa27AAr35FRqU98DJu1fXES56uXniYFv4yDA= github.com/actgardner/gogen-avro/v10 v10.2.1/go.mod h1:QUhjeHPchheYmMDni/Nx7VB0RsT/ee8YIgGY/xpEQgQ= @@ -46,6 +50,8 @@ github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= +github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh2R/Yv3E= github.com/btcsuite/btcd/btcec/v2 v2.2.1/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8= @@ -67,10 +73,12 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= -github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= +github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14 h1:4spJmU4jzTXRbaQV9yrGHBDL/nTgaebjbW4Qidtkz0w= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/confluentinc/confluent-kafka-go v1.9.2 h1:gV/GxhMBUb03tFWkN+7kdhg+zf+QUM+wVkI9zwh770Q= github.com/confluentinc/confluent-kafka-go v1.9.2/go.mod h1:ptXNqsuDfYbAE/LBW6pnwWZElUoWxHoV8E43DCrliyo= +github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqqExkAtyks= +github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -99,6 +107,8 @@ github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= +github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -236,6 +246,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a h1:dHCfT5W7gghzPtfsW488uPmEOm85wewI+ypUwibyTdU= github.com/linkedin/goavro v2.1.0+incompatible/go.mod h1:bBCwI2eGYpUI/4820s67MElg9tdeLbINjLjiM2xZFYM= github.com/linkedin/goavro/v2 v2.9.7/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA= github.com/linkedin/goavro/v2 v2.10.0/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA= @@ -298,8 +309,6 @@ github.com/santhosh-tekuri/jsonschema/v5 v5.1.1 h1:lEOLY2vyGIqKWUI9nzsOJRV3mb3WC github.com/santhosh-tekuri/jsonschema/v5 v5.1.1/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= -github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a h1:8lHQYdub7q3LgD5ebQOA+usDyUqqiHvKEJPGQ8+FxMA= github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a/go.mod h1:Nt4mQh6z6q26jrM4FyQLq/2vBp1Sg3l5md3tBRdRLxg= github.com/smartcontractkit/libocr v0.0.0-20230802221916-2271752fa829 h1:fzefK1SzoRSHzZduOCzIJ2kmkBMPKwIf3FgeBlw7Jjk= @@ -321,12 +330,16 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE= +github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU= github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.5.0 h1:ooe7gN0fg6myJ0EKoTAf5hebTZrH52px3New/D9iJ+A= github.com/tklauser/numcpus v0.5.0/go.mod h1:OGzpTxpcIMNGYQdit2BYL1pvk/dSOaJWjKoflh+RQjo= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/monitoring/pkg/monitoring/source_envelope.go b/monitoring/pkg/monitoring/source_envelope.go index ac4bd9266..871a1d970 100644 --- a/monitoring/pkg/monitoring/source_envelope.go +++ b/monitoring/pkg/monitoring/source_envelope.go @@ -6,7 +6,9 @@ import ( "math/big" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" relayUtils "github.com/smartcontractkit/chainlink-relay/pkg/utils" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -36,9 +38,17 @@ func (s *envelopeSourceFactory) NewSource( if !ok { return nil, fmt.Errorf("expected feedConfig to be of type StarknetFeedConfig not %T", feedConfig) } + contractAddress, err := starknetutils.HexToFelt(feedConfig.GetContractAddress()) + if err != nil { + return nil, err + } + linkTokenAddress, err := starknetutils.HexToFelt(starknetChainConfig.GetLinkTokenAddress()) + if err != nil { + return nil, err + } return &envelopeSource{ - caigotypes.StrToFelt(feedConfig.GetContractAddress()), - caigotypes.StrToFelt(starknetChainConfig.GetLinkTokenAddress()), + contractAddress, + linkTokenAddress, s.ocr2Reader, }, nil } @@ -48,8 +58,8 @@ func (s *envelopeSourceFactory) GetType() string { } type envelopeSource struct { - contractAddress caigotypes.Felt - linkTokenAddress caigotypes.Felt + contractAddress *felt.Felt + linkTokenAddress *felt.Felt ocr2Reader ocr2.OCR2Reader } @@ -115,7 +125,7 @@ func (s *envelopeSource) Fetch(ctx context.Context) (interface{}, error) { return envelope, envelopeErr } -func (s *envelopeSource) fetchLatestNewTransmissionEvent(ctx context.Context, contractAddress caigotypes.Felt) ( +func (s *envelopeSource) fetchLatestNewTransmissionEvent(ctx context.Context, contractAddress *felt.Felt) ( latestRound ocr2.RoundData, transmission ocr2.NewTransmissionEvent, err error, @@ -141,7 +151,7 @@ func (s *envelopeSource) fetchLatestNewTransmissionEvent(ctx context.Context, co return latestRound, transmission, fmt.Errorf("no new_trasmission event found to correspond with the round id %d in block %d", latestRound.RoundID, latestRound.BlockNumber) } -func (s *envelopeSource) fetchContractConfig(ctx context.Context, contractAddress caigotypes.Felt) (config ocr2.ContractConfig, err error) { +func (s *envelopeSource) fetchContractConfig(ctx context.Context, contractAddress *felt.Felt) (config ocr2.ContractConfig, err error) { configDetails, err := s.ocr2Reader.LatestConfigDetails(ctx, contractAddress) if err != nil { return config, fmt.Errorf("couldn't fetch latest config details for contract '%s': %w", contractAddress, err) @@ -155,11 +165,11 @@ func (s *envelopeSource) fetchContractConfig(ctx context.Context, contractAddres var zeroBigInt = big.NewInt(0) -func (s *envelopeSource) fetchLinkBalance(ctx context.Context, linkTokenAddress, contractAddress caigotypes.Felt) (*big.Int, error) { +func (s *envelopeSource) fetchLinkBalance(ctx context.Context, linkTokenAddress, contractAddress *felt.Felt) (*big.Int, error) { results, err := s.ocr2Reader.BaseReader().CallContract(ctx, starknet.CallOps{ ContractAddress: linkTokenAddress, - Selector: "balanceOf", - Calldata: []string{contractAddress.String()}, + Selector: starknettypes.GetSelectorFromNameFelt("balanceOf"), + Calldata: []*felt.Felt{contractAddress}, }) if err != nil { return nil, fmt.Errorf("failed call to ECR20 contract, balanceOf method: %w", err) @@ -167,7 +177,7 @@ func (s *envelopeSource) fetchLinkBalance(ctx context.Context, linkTokenAddress, if len(results) < 1 { return nil, fmt.Errorf("insufficient data from balanceOf '%v': %w", results, err) } - linkBalance := caigotypes.HexToBN(results[0]) + linkBalance := results[0].BigInt(big.NewInt(0)) if linkBalance.Cmp(zeroBigInt) == 0 { return nil, fmt.Errorf("contract's LINK balance should not be zero") } diff --git a/monitoring/pkg/monitoring/source_envelope_test.go b/monitoring/pkg/monitoring/source_envelope_test.go index d46cf7ab6..b3b38ff75 100644 --- a/monitoring/pkg/monitoring/source_envelope_test.go +++ b/monitoring/pkg/monitoring/source_envelope_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/starknet.go" + starknettypes "github.com/NethermindEth/starknet.go/types" relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/stretchr/testify/mock" @@ -65,7 +65,7 @@ func TestEnvelopeSource(t *testing.T) { ContractAddress: chainConfig.GetLinkTokenAddress(), Selector: "balanceOf", Calldata: []string{ - caigo.HexToBN(feedConfig.ContractAddress).String(), + starknetgo.HexToBN(feedConfig.ContractAddress).String(), }, }, ).Return(starknetReaderCallContractBalanceOfResponse, nil) @@ -93,7 +93,7 @@ var ( { RoundId: 0xf5b, LatestAnswer: bigIntFromString("-900000000"), - Transmitter: caigotypes.StrToFelt("634447934223750826572902672583054702307815157196919304685470566142330202833"), + Transmitter: starknettypes.StrToFelt("634447934223750826572902672583054702307815157196919304685470566142330202833"), LatestTimestamp: time.Date(2022, time.September, 27, 18, 51, 0, 0, time.Local), Observers: []uint8{0x1, 0x2, 0x3, 0x4}, ObservationsLen: 0x4, diff --git a/monitoring/pkg/monitoring/source_proxy.go b/monitoring/pkg/monitoring/source_proxy.go index 2cc5e76ba..a8bb9932a 100644 --- a/monitoring/pkg/monitoring/source_proxy.go +++ b/monitoring/pkg/monitoring/source_proxy.go @@ -5,7 +5,8 @@ import ( "fmt" "math/big" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2" @@ -31,8 +32,12 @@ func (s *proxySourceFactory) NewSource( _ relayMonitoring.ChainConfig, feedConfig relayMonitoring.FeedConfig, ) (relayMonitoring.Source, error) { + contractAddress, err := starknetutils.HexToFelt(feedConfig.GetContractAddress()) + if err != nil { + return nil, err + } return &proxySource{ - caigotypes.HexToHash(feedConfig.GetContractAddress()), + contractAddress, s.ocr2Reader, }, nil } @@ -42,7 +47,7 @@ func (s *proxySourceFactory) GetType() string { } type proxySource struct { - contractAddress caigotypes.Hash + contractAddress *felt.Felt ocr2Reader ocr2.OCR2Reader } diff --git a/monitoring/pkg/monitoring/source_txresults.go b/monitoring/pkg/monitoring/source_txresults.go index f3c9de980..06c44cae5 100644 --- a/monitoring/pkg/monitoring/source_txresults.go +++ b/monitoring/pkg/monitoring/source_txresults.go @@ -5,7 +5,8 @@ import ( "fmt" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2" @@ -27,8 +28,12 @@ func (s *txResultsSourceFactory) NewSource( _ relayMonitoring.ChainConfig, feedConfig relayMonitoring.FeedConfig, ) (relayMonitoring.Source, error) { + contractAddress, err := starknetutils.HexToFelt(feedConfig.GetContractAddress()) + if err != nil { + return nil, err + } return &txResultsSource{ - caigotypes.HexToHash(feedConfig.GetContractAddress()), + contractAddress, s.ocr2Reader, 0, sync.Mutex{}, @@ -40,7 +45,7 @@ func (s *txResultsSourceFactory) GetType() string { } type txResultsSource struct { - contractAddress caigotypes.Hash + contractAddress *felt.Felt ocr2Reader ocr2.OCR2Reader prevRoundID uint32 diff --git a/ops/devnet/devnet.go b/ops/devnet/devnet.go index 8b886b54f..13f40540d 100644 --- a/ops/devnet/devnet.go +++ b/ops/devnet/devnet.go @@ -6,7 +6,7 @@ import ( "strings" "time" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2" "github.com/go-resty/resty/v2" @@ -74,6 +74,7 @@ func (devnet *StarknetDevnetClient) AutoDumpState() { // AutoLoadState auto loads last saved devnet state on contract not found func (devnet *StarknetDevnetClient) AutoLoadState(client *ocr2.Client, ocrAddress string) { + addr, _ := starknetutils.HexToFelt(ocrAddress) t := time.NewTicker(15 * time.Second) go func() { for { @@ -83,7 +84,8 @@ func (devnet *StarknetDevnetClient) AutoLoadState(client *ocr2.Client, ocrAddres return case <-t.C: log.Debug().Msg("Checking for devnet OCR contract errors") - _, err := client.LatestTransmissionDetails(devnet.ctx, caigotypes.StrToFelt(ocrAddress)) + + _, err := client.LatestTransmissionDetails(devnet.ctx, addr) if err != nil && strings.Contains(err.Error(), "is not deployed") { _, err = devnet.client.R().SetBody(map[string]any{ "path": devnet.dumpPath, diff --git a/ops/go.mod b/ops/go.mod index 811eb8f7e..e742433c8 100644 --- a/ops/go.mod +++ b/ops/go.mod @@ -3,9 +3,9 @@ module github.com/smartcontractkit/chainlink-starknet/ops go 1.20 require ( + github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3 github.com/go-resty/resty/v2 v2.7.0 github.com/rs/zerolog v1.29.1 - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-env v0.3.29 github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20230530233948-90c8af98011e github.com/smartcontractkit/chainlink-testing-framework v1.11.5 @@ -15,6 +15,7 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/MakeNowJust/heredoc v1.0.0 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect + github.com/NethermindEth/juno v0.3.1 // indirect github.com/VictoriaMetrics/fastcache v1.10.0 // indirect github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/avast/retry-go v3.0.0+incompatible // indirect @@ -22,11 +23,13 @@ require ( github.com/aws/jsii-runtime-go v1.75.0 // indirect github.com/benbjohnson/clock v1.3.4 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.7.5 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect github.com/chaos-mesh/chaos-mesh/api/v1alpha1 v0.0.0-20220226050744-799408773657 // indirect + github.com/consensys/gnark-crypto v0.11.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect @@ -40,6 +43,7 @@ require ( github.com/fatih/color v1.15.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fvbommel/sortorder v1.0.2 // indirect + github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/getsentry/sentry-go v0.19.0 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-logr/logr v1.2.4 // indirect @@ -109,8 +113,10 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect + github.com/test-go/testify v1.1.4 // indirect github.com/tklauser/go-sysconf v0.3.11 // indirect github.com/tklauser/numcpus v0.6.0 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/xlab/treeprint v1.1.0 // indirect github.com/yuin/goldmark v1.4.13 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect diff --git a/ops/go.sum b/ops/go.sum index 2155660bb..1a2d852b2 100644 --- a/ops/go.sum +++ b/ops/go.sum @@ -44,6 +44,10 @@ github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/NethermindEth/juno v0.3.1 h1:AW72LiAm9gqUeCVJWvepnZcTnpU4Vkl0KzPMxS+42FA= +github.com/NethermindEth/juno v0.3.1/go.mod h1:SGbTpgGaCsxhFsKOid7Ylnz//WZ8swtILk+NbHGsk/Q= +github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3 h1:SAE7oDXo82lT+arBtg6sozPMt9bNSkXY1A2TxlCGRw4= +github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3/go.mod h1:4fchLnLzJuwl1bnNUR+iBjKYN11afzJCdBcGZKIuFeU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/VictoriaMetrics/fastcache v1.10.0 h1:5hDJnLsKLpnUEToub7ETuRu8RCkb40woBZAUiKonXzY= github.com/VictoriaMetrics/fastcache v1.10.0/go.mod h1:tjiYeEfYXCqacuvYw/7UoDIeJaNxq6132xHICNP77w8= @@ -62,6 +66,8 @@ github.com/benbjohnson/clock v1.3.4 h1:wj3BFPrTw8yYgA1OlMqvUk95nc8OMv3cvBSF5erT2 github.com/benbjohnson/clock v1.3.4/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= +github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= @@ -89,8 +95,10 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= -github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= +github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14 h1:4spJmU4jzTXRbaQV9yrGHBDL/nTgaebjbW4Qidtkz0w= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= +github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqqExkAtyks= +github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -139,6 +147,8 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4 github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fvbommel/sortorder v1.0.2 h1:mV4o8B2hKboCdkJm+a7uX/SIpZob4JzUpc5GGnM45eo= github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0= +github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= +github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= github.com/getsentry/sentry-go v0.19.0 h1:BcCH3CN5tXt5aML+gwmbFwVptLLQA+eT866fCO9wVOM= github.com/getsentry/sentry-go v0.19.0/go.mod h1:y3+lGEFEFexZtpbG1GUE2WD/f9zGyKYwpEqryTOC/nE= @@ -299,6 +309,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a h1:dHCfT5W7gghzPtfsW488uPmEOm85wewI+ypUwibyTdU= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -393,8 +404,6 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= -github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-env v0.3.29 h1:hcIw/BeuB0wKiiE3umAUNBZzWkHO24XF3OW9xSrlMbI= github.com/smartcontractkit/chainlink-env v0.3.29/go.mod h1:9c0Czq4a6wZKY20BcoAlK29DnejQIiLo/MwKYtSFnHk= github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a h1:8lHQYdub7q3LgD5ebQOA+usDyUqqiHvKEJPGQ8+FxMA= @@ -428,11 +437,15 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= +github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE= +github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/relayer/go.mod b/relayer/go.mod index 820355cdd..7e4d1ca12 100644 --- a/relayer/go.mod +++ b/relayer/go.mod @@ -3,10 +3,11 @@ module github.com/smartcontractkit/chainlink-starknet/relayer go 1.20 require ( + github.com/NethermindEth/juno v0.3.1 + github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3 github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 github.com/ethereum/go-ethereum v1.11.5 github.com/pkg/errors v0.9.1 - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a github.com/smartcontractkit/libocr v0.0.0-20230802221916-2271752fa829 github.com/stretchr/testify v1.8.4 @@ -17,13 +18,16 @@ require ( require ( github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/consensys/gnark-crypto v0.11.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect @@ -54,8 +58,10 @@ require ( github.com/prometheus/procfs v0.9.0 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/stretchr/objx v0.5.0 // indirect + github.com/test-go/testify v1.1.4 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.5.0 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect go.opentelemetry.io/otel v1.16.0 // indirect diff --git a/relayer/go.sum b/relayer/go.sum index b61767b3d..ff10c9d3e 100644 --- a/relayer/go.sum +++ b/relayer/go.sum @@ -37,11 +37,17 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= +github.com/NethermindEth/juno v0.3.1 h1:AW72LiAm9gqUeCVJWvepnZcTnpU4Vkl0KzPMxS+42FA= +github.com/NethermindEth/juno v0.3.1/go.mod h1:SGbTpgGaCsxhFsKOid7Ylnz//WZ8swtILk+NbHGsk/Q= +github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3 h1:SAE7oDXo82lT+arBtg6sozPMt9bNSkXY1A2TxlCGRw4= +github.com/NethermindEth/starknet.go v0.4.2-0.20230830055456-308b763a11d3/go.mod h1:4fchLnLzJuwl1bnNUR+iBjKYN11afzJCdBcGZKIuFeU= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= +github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh2R/Yv3E= github.com/btcsuite/btcd/btcec/v2 v2.2.1/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= @@ -58,8 +64,10 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= -github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk= +github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14 h1:4spJmU4jzTXRbaQV9yrGHBDL/nTgaebjbW4Qidtkz0w= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= +github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqqExkAtyks= +github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -82,6 +90,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= +github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -193,6 +203,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a h1:dHCfT5W7gghzPtfsW488uPmEOm85wewI+ypUwibyTdU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -234,8 +245,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= -github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a h1:8lHQYdub7q3LgD5ebQOA+usDyUqqiHvKEJPGQ8+FxMA= github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230808141159-4e20b0757f3a/go.mod h1:Nt4mQh6z6q26jrM4FyQLq/2vBp1Sg3l5md3tBRdRLxg= github.com/smartcontractkit/libocr v0.0.0-20230802221916-2271752fa829 h1:fzefK1SzoRSHzZduOCzIJ2kmkBMPKwIf3FgeBlw7Jjk= @@ -254,12 +263,16 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE= +github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU= github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.5.0 h1:ooe7gN0fg6myJ0EKoTAf5hebTZrH52px3New/D9iJ+A= github.com/tklauser/numcpus v0.5.0/go.mod h1:OGzpTxpcIMNGYQdit2BYL1pvk/dSOaJWjKoflh+RQjo= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/relayer/pkg/chainlink/ocr2/client.go b/relayer/pkg/chainlink/ocr2/client.go index 6548aa0af..ce30d47de 100644 --- a/relayer/pkg/chainlink/ocr2/client.go +++ b/relayer/pkg/chainlink/ocr2/client.go @@ -8,8 +8,9 @@ import ( "github.com/pkg/errors" - caigorpc "github.com/smartcontractkit/caigo/rpcv02" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" + starknettypes "github.com/NethermindEth/starknet.go/types" "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet" @@ -20,13 +21,13 @@ import ( //go:generate mockery --name OCR2Reader --output ./mocks/ type OCR2Reader interface { - LatestConfigDetails(context.Context, caigotypes.Felt) (ContractConfigDetails, error) - LatestTransmissionDetails(context.Context, caigotypes.Felt) (TransmissionDetails, error) - LatestRoundData(context.Context, caigotypes.Felt) (RoundData, error) - LinkAvailableForPayment(context.Context, caigotypes.Felt) (*big.Int, error) - ConfigFromEventAt(context.Context, caigotypes.Felt, uint64) (ContractConfig, error) - NewTransmissionsFromEventsAt(context.Context, caigotypes.Felt, uint64) ([]NewTransmissionEvent, error) - BillingDetails(context.Context, caigotypes.Felt) (BillingDetails, error) + LatestConfigDetails(context.Context, *felt.Felt) (ContractConfigDetails, error) + LatestTransmissionDetails(context.Context, *felt.Felt) (TransmissionDetails, error) + LatestRoundData(context.Context, *felt.Felt) (RoundData, error) + LinkAvailableForPayment(context.Context, *felt.Felt) (*big.Int, error) + ConfigFromEventAt(context.Context, *felt.Felt, uint64) (ContractConfig, error) + NewTransmissionsFromEventsAt(context.Context, *felt.Felt, uint64) ([]NewTransmissionEvent, error) + BillingDetails(context.Context, *felt.Felt) (BillingDetails, error) BaseReader() starknet.Reader } @@ -49,10 +50,10 @@ func (c *Client) BaseReader() starknet.Reader { return c.r } -func (c *Client) BillingDetails(ctx context.Context, address caigotypes.Felt) (bd BillingDetails, err error) { +func (c *Client) BillingDetails(ctx context.Context, address *felt.Felt) (bd BillingDetails, err error) { ops := starknet.CallOps{ ContractAddress: address, - Selector: "billing", + Selector: starknettypes.GetSelectorFromNameFelt("billing"), } res, err := c.r.CallContract(ctx, ops) @@ -65,8 +66,8 @@ func (c *Client) BillingDetails(ctx context.Context, address caigotypes.Felt) (b return bd, errors.New("unexpected result length") } - observationPayment := caigotypes.StrToFelt(res[0]).Big() - transmissionPayment := caigotypes.StrToFelt(res[1]).Big() + observationPayment := res[0].BigInt(big.NewInt(0)) + transmissionPayment := res[1].BigInt(big.NewInt(0)) bd, err = NewBillingDetails(observationPayment, transmissionPayment) if err != nil { @@ -76,10 +77,10 @@ func (c *Client) BillingDetails(ctx context.Context, address caigotypes.Felt) (b return } -func (c *Client) LatestConfigDetails(ctx context.Context, address caigotypes.Felt) (ccd ContractConfigDetails, err error) { +func (c *Client) LatestConfigDetails(ctx context.Context, address *felt.Felt) (ccd ContractConfigDetails, err error) { ops := starknet.CallOps{ ContractAddress: address, - Selector: "latest_config_details", + Selector: starknettypes.GetSelectorFromNameFelt("latest_config_details"), } res, err := c.r.CallContract(ctx, ops) @@ -92,10 +93,10 @@ func (c *Client) LatestConfigDetails(ctx context.Context, address caigotypes.Fel return ccd, errors.New("unexpected result length") } - blockNum := caigotypes.StrToFelt(res[1]) - configDigest := caigotypes.StrToFelt(res[2]) + blockNum := res[1] + configDigest := res[2] - ccd, err = NewContractConfigDetails(blockNum.Big(), configDigest.Bytes()) + ccd, err = NewContractConfigDetails(blockNum.BigInt(big.NewInt((0))), configDigest.Bytes()) if err != nil { return ccd, errors.Wrap(err, "couldn't initialize config details") } @@ -103,10 +104,10 @@ func (c *Client) LatestConfigDetails(ctx context.Context, address caigotypes.Fel return } -func (c *Client) LatestTransmissionDetails(ctx context.Context, address caigotypes.Felt) (td TransmissionDetails, err error) { +func (c *Client) LatestTransmissionDetails(ctx context.Context, address *felt.Felt) (td TransmissionDetails, err error) { ops := starknet.CallOps{ ContractAddress: address, - Selector: "latest_transmission_details", + Selector: starknettypes.GetSelectorFromNameFelt("latest_transmission_details"), } res, err := c.r.CallContract(ctx, ops) @@ -119,20 +120,20 @@ func (c *Client) LatestTransmissionDetails(ctx context.Context, address caigotyp return td, errors.New("unexpected result length") } - digest := caigotypes.StrToFelt(res[0]) + digest := res[0] configDigest := types.ConfigDigest{} - digest.Big().FillBytes(configDigest[:]) + digest.BigInt(big.NewInt(0)).FillBytes(configDigest[:]) - epoch, round := parseEpochAndRound(caigotypes.StrToFelt(res[1]).Big()) + epoch, round := parseEpochAndRound(res[1].BigInt(big.NewInt(0))) - latestAnswer, err := starknet.HexToUnsignedBig(res[2]) + latestAnswer := res[2].BigInt(big.NewInt(0)) if err != nil { return td, errors.Wrap(err, "latestAnswer invalid") } - timestampFelt := caigotypes.StrToFelt(res[3]) + timestampFelt := res[3] // TODO: Int64() can return invalid data if int is too big - unixTime := timestampFelt.Big().Int64() + unixTime := timestampFelt.BigInt(big.NewInt(0)).Int64() latestTimestamp := time.Unix(unixTime, 0) td = TransmissionDetails{ @@ -146,20 +147,16 @@ func (c *Client) LatestTransmissionDetails(ctx context.Context, address caigotyp return td, nil } -func (c *Client) LatestRoundData(ctx context.Context, address caigotypes.Felt) (round RoundData, err error) { +func (c *Client) LatestRoundData(ctx context.Context, address *felt.Felt) (round RoundData, err error) { ops := starknet.CallOps{ ContractAddress: address, - Selector: "latest_round_data", + Selector: starknettypes.GetSelectorFromNameFelt("latest_round_data"), } - results, err := c.r.CallContract(ctx, ops) + felts, err := c.r.CallContract(ctx, ops) if err != nil { return round, errors.Wrap(err, "couldn't call the contract with selector latest_round_data") } - felts := []caigotypes.Felt{} - for _, result := range results { - felts = append(felts, caigotypes.StrToFelt(result)) - } round, err = NewRoundData(felts) if err != nil { @@ -168,10 +165,10 @@ func (c *Client) LatestRoundData(ctx context.Context, address caigotypes.Felt) ( return round, nil } -func (c *Client) LinkAvailableForPayment(ctx context.Context, address caigotypes.Felt) (*big.Int, error) { +func (c *Client) LinkAvailableForPayment(ctx context.Context, address *felt.Felt) (*big.Int, error) { results, err := c.r.CallContract(ctx, starknet.CallOps{ ContractAddress: address, - Selector: "link_available_for_payment", + Selector: starknettypes.GetSelectorFromNameFelt("link_available_for_payment"), }) if err != nil { return nil, errors.Wrap(err, "failed to call the contract with selector 'link_available_for_payment'") @@ -179,24 +176,24 @@ func (c *Client) LinkAvailableForPayment(ctx context.Context, address caigotypes if len(results) != 1 { return nil, errors.Wrap(err, "insufficient data from selector 'link_available_for_payment'") } - return caigotypes.HexToBN(results[0]), nil + return results[0].BigInt(big.NewInt(0)), nil } -func (c *Client) fetchEventsFromBlock(ctx context.Context, address caigotypes.Felt, eventType string, blockNum uint64) (eventsAsFeltArrs [][]caigotypes.Felt, err error) { - block := caigorpc.WithBlockNumber(blockNum) +func (c *Client) fetchEventsFromBlock(ctx context.Context, address *felt.Felt, eventType string, blockNum uint64) (eventsAsFeltArrs [][]*felt.Felt, err error) { + block := starknetrpc.WithBlockNumber(blockNum) - eventKey := caigotypes.BigToHex(caigotypes.GetSelectorFromName(eventType)) + eventKey := starknettypes.GetSelectorFromNameFelt(eventType) - input := caigorpc.EventsInput{ - EventFilter: caigorpc.EventFilter{ + input := starknetrpc.EventsInput{ + EventFilter: starknetrpc.EventFilter{ FromBlock: block, ToBlock: block, Address: address, - Keys: [][]string{{eventKey}}, // skip other event types + Keys: [][]*felt.Felt{{eventKey}}, // skip other event types // PageSize: 0, // PageNumber: 0, }, - ResultPageRequest: caigorpc.ResultPageRequest{ + ResultPageRequest: starknetrpc.ResultPageRequest{ // ContinuationToken: , ChunkSize: 10, }, @@ -210,12 +207,7 @@ func (c *Client) fetchEventsFromBlock(ctx context.Context, address caigotypes.Fe } for _, event := range events.Events { - // convert to felts - felts := []caigotypes.Felt{} - for _, felt := range event.Data { - felts = append(felts, caigotypes.StrToFelt(felt)) - } - eventsAsFeltArrs = append(eventsAsFeltArrs, felts) + eventsAsFeltArrs = append(eventsAsFeltArrs, event.Data) } if len(eventsAsFeltArrs) == 0 { return nil, errors.New("events not found in the block") @@ -223,7 +215,7 @@ func (c *Client) fetchEventsFromBlock(ctx context.Context, address caigotypes.Fe return eventsAsFeltArrs, nil } -func (c *Client) ConfigFromEventAt(ctx context.Context, address caigotypes.Felt, blockNum uint64) (cc ContractConfig, err error) { +func (c *Client) ConfigFromEventAt(ctx context.Context, address *felt.Felt, blockNum uint64) (cc ContractConfig, err error) { eventsAsFeltArrs, err := c.fetchEventsFromBlock(ctx, address, "ConfigSet", blockNum) if err != nil { return cc, errors.Wrap(err, "failed to fetch config_set events") @@ -243,7 +235,7 @@ func (c *Client) ConfigFromEventAt(ctx context.Context, address caigotypes.Felt, } // NewTransmissionsFromEventsAt finds events of type new_transmission emitted by the contract address in a given block number. -func (c *Client) NewTransmissionsFromEventsAt(ctx context.Context, address caigotypes.Felt, blockNum uint64) (events []NewTransmissionEvent, err error) { +func (c *Client) NewTransmissionsFromEventsAt(ctx context.Context, address *felt.Felt, blockNum uint64) (events []NewTransmissionEvent, err error) { eventsAsFeltArrs, err := c.fetchEventsFromBlock(ctx, address, "NewTransmission", blockNum) if err != nil { return nil, errors.Wrap(err, "failed to fetch new_transmission events") diff --git a/relayer/pkg/chainlink/ocr2/client_test.go b/relayer/pkg/chainlink/ocr2/client_test.go index 5e4c9aeb7..71aebafbc 100644 --- a/relayer/pkg/chainlink/ocr2/client_test.go +++ b/relayer/pkg/chainlink/ocr2/client_test.go @@ -11,8 +11,9 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo/gateway" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/starknet.go/gateway" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -56,24 +57,25 @@ func TestOCR2Client(t *testing.T) { err := json.Unmarshal([]byte(raw), &reqdata) require.NoError(t, err) - switch { - case caigotypes.BigToHex(caigotypes.GetSelectorFromName("billing")) == reqdata.Selector: + fmt.Printf("%v %v\n", reqdata.Selector, starknettypes.GetSelectorFromNameFelt("latest_transmission_details").String()) + switch reqdata.Selector { + case starknettypes.GetSelectorFromNameFelt("billing").String(): // billing response out = []byte(`{"result":["0x0","0x0","0x0","0x0"]}`) - case caigotypes.BigToHex(caigotypes.GetSelectorFromName("latest_config_details")) == reqdata.Selector: + case starknettypes.GetSelectorFromNameFelt("latest_config_details").String(): // latest config details response out = []byte(`{"result":["0x1","0x2","0x4b791b801cf0d7b6a2f9e59daf15ec2dd7d9cdc3bc5e037bada9c86e4821c"]}`) - case caigotypes.BigToHex(caigotypes.GetSelectorFromName("latest_transmission_details")) == reqdata.Selector: + case starknettypes.GetSelectorFromNameFelt("latest_transmission_details").String(): // latest transmission details response out = []byte(`{"result":["0x4cfc96325fa7d72e4854420e2d7b0abda72de17d45e4c3c0d9f626016d669","0x0","0x0","0x0"]}`) - case caigotypes.BigToHex(caigotypes.GetSelectorFromName("latest_round_data")) == reqdata.Selector: + case starknettypes.GetSelectorFromNameFelt("latest_round_data").String(): // latest transmission details response out = []byte(`{"result":["0x0","0x0","0x0","0x0","0x0"]}`) - case caigotypes.BigToHex(caigotypes.GetSelectorFromName("link_available_for_payment")) == reqdata.Selector: + case starknettypes.GetSelectorFromNameFelt("link_available_for_payment").String(): // latest transmission details response out = []byte(`{"result":["0x0"]}`) default: - require.False(t, true, "unsupported contract method") + require.False(t, true, "unsupported contract method %s", reqdata.Selector) } case "starknet_getEvents": out = []byte(BLOCK_OUTPUT) @@ -98,7 +100,8 @@ func TestOCR2Client(t *testing.T) { client, err := NewClient(reader, lggr) assert.NoError(t, err) - contractAddress := caigotypes.StrToFelt(ocr2ContractAddress) + contractAddress, err := starknetutils.HexToFelt(ocr2ContractAddress) + require.NoError(t, err) t.Run("get billing details", func(t *testing.T) { billing, err := client.BillingDetails(context.Background(), contractAddress) diff --git a/relayer/pkg/chainlink/ocr2/config_digester.go b/relayer/pkg/chainlink/ocr2/config_digester.go index f61f22c93..a7f96324a 100644 --- a/relayer/pkg/chainlink/ocr2/config_digester.go +++ b/relayer/pkg/chainlink/ocr2/config_digester.go @@ -6,7 +6,7 @@ import ( "math/big" "strings" - "github.com/smartcontractkit/caigo" + "github.com/NethermindEth/starknet.go" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -90,7 +90,7 @@ func (d offchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.Co ) msg = append(msg, offchainConfig...) // offchain_config - digest, err := caigo.Curve.ComputeHashOnElements(msg) + digest, err := starknetgo.Curve.ComputeHashOnElements(msg) if err != nil { return configDigest, err } diff --git a/relayer/pkg/chainlink/ocr2/contract_reader.go b/relayer/pkg/chainlink/ocr2/contract_reader.go index 0a433bdf4..24be20bd9 100644 --- a/relayer/pkg/chainlink/ocr2/contract_reader.go +++ b/relayer/pkg/chainlink/ocr2/contract_reader.go @@ -5,8 +5,9 @@ import ( "math/big" "time" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" "github.com/pkg/errors" - caigotypes "github.com/smartcontractkit/caigo/types" "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" @@ -21,14 +22,19 @@ type Reader interface { var _ Reader = (*contractReader)(nil) type contractReader struct { - address caigotypes.Felt + address *felt.Felt reader OCR2Reader lggr logger.Logger } func NewContractReader(address string, reader OCR2Reader, lggr logger.Logger) Reader { + felt, err := starknetutils.HexToFelt(address) + if err != nil { + panic("invalid felt value") + } + return &contractReader{ - address: caigotypes.StrToFelt(address), // TODO: propagate type everywhere + address: felt, // TODO: propagate type everywhere reader: reader, lggr: lggr, } diff --git a/relayer/pkg/chainlink/ocr2/contract_transmitter.go b/relayer/pkg/chainlink/ocr2/contract_transmitter.go index 88c50d96a..aa0a323c6 100644 --- a/relayer/pkg/chainlink/ocr2/contract_transmitter.go +++ b/relayer/pkg/chainlink/ocr2/contract_transmitter.go @@ -7,7 +7,9 @@ import ( "github.com/pkg/errors" - caigotypes "github.com/smartcontractkit/caigo/types" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2/medianreport" "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/txm" @@ -20,9 +22,9 @@ var _ types.ContractTransmitter = (*contractTransmitter)(nil) type contractTransmitter struct { reader *transmissionsCache - contractAddress caigotypes.Felt - senderAddress caigotypes.Felt - accountAddress caigotypes.Felt + contractAddress *felt.Felt + senderAddress *felt.Felt + accountAddress *felt.Felt txm txm.TxManager } @@ -34,11 +36,15 @@ func NewContractTransmitter( accountAddress string, txm txm.TxManager, ) *contractTransmitter { + contractAddr, _ := starknetutils.HexToFelt(contractAddress) + senderAddr, _ := starknetutils.HexToFelt(senderAddress) + accountAddr, _ := starknetutils.HexToFelt(accountAddress) + return &contractTransmitter{ reader: reader, - contractAddress: caigotypes.StrToFelt(contractAddress), - senderAddress: caigotypes.StrToFelt(senderAddress), - accountAddress: caigotypes.StrToFelt(accountAddress), + contractAddress: contractAddr, + senderAddress: senderAddr, + accountAddress: accountAddr, txm: txm, } } @@ -84,10 +90,16 @@ func (c *contractTransmitter) Transmit( transmitPayload = append(transmitPayload, "0x"+hex.EncodeToString(signature[:32])) // public key } - err = c.txm.Enqueue(c.senderAddress, c.accountAddress, caigotypes.FunctionCall{ + // TODO: build felts directly rather than afterwards + calldata, err := starknetutils.HexArrToFelt(transmitPayload) + if err != nil { + return err + } + + err = c.txm.Enqueue(c.senderAddress, c.accountAddress, starknettypes.FunctionCall{ ContractAddress: c.contractAddress, - EntryPointSelector: "transmit", - Calldata: transmitPayload, + EntryPointSelector: starknettypes.GetSelectorFromNameFelt("transmit"), + Calldata: calldata, }) return err diff --git a/relayer/pkg/chainlink/ocr2/events.go b/relayer/pkg/chainlink/ocr2/events.go index 1be0c6660..01bf67c84 100644 --- a/relayer/pkg/chainlink/ocr2/events.go +++ b/relayer/pkg/chainlink/ocr2/events.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -26,7 +26,7 @@ var ( type NewTransmissionEvent struct { RoundId uint32 LatestAnswer *big.Int - Transmitter caigotypes.Felt + Transmitter *felt.Felt LatestTimestamp time.Time Observers []uint8 ObservationsLen uint32 @@ -40,7 +40,7 @@ type NewTransmissionEvent struct { } // ParseNewTransmissionEvent is decoding binary felt data as the NewTransmissionEvent type -func ParseNewTransmissionEvent(eventData []caigotypes.Felt) (NewTransmissionEvent, error) { +func ParseNewTransmissionEvent(eventData []*felt.Felt) (NewTransmissionEvent, error) { { const observationsLenIndex = 5 const constNumOfElements = 11 @@ -49,7 +49,7 @@ func ParseNewTransmissionEvent(eventData []caigotypes.Felt) (NewTransmissionEven return NewTransmissionEvent{}, errors.New("invalid: event data") } - observationsLen := eventData[observationsLenIndex].Big().Uint64() + observationsLen := eventData[observationsLenIndex].BigInt(big.NewInt(0)).Uint64() if len(eventData) != constNumOfElements+int(observationsLen) { return NewTransmissionEvent{}, errors.New("invalid: event data") } @@ -57,14 +57,11 @@ func ParseNewTransmissionEvent(eventData []caigotypes.Felt) (NewTransmissionEven // round_id index := 0 - roundId := uint32(eventData[index].Big().Uint64()) + roundId := uint32(eventData[index].BigInt(big.NewInt(0)).Uint64()) // answer index++ - latestAnswer, err := starknet.HexToUnsignedBig(eventData[index].String()) - if err != nil { - return NewTransmissionEvent{}, errors.Wrap(err, "latestAnswer invalid") - } + latestAnswer := eventData[index].BigInt(big.NewInt(0)) // transmitter index++ @@ -72,16 +69,16 @@ func ParseNewTransmissionEvent(eventData []caigotypes.Felt) (NewTransmissionEven // observation_timestamp index++ - unixTime := eventData[index].Big().Int64() + unixTime := eventData[index].BigInt(big.NewInt(0)).Int64() latestTimestamp := time.Unix(unixTime, 0) // observers (raw) max 31 index++ - observersRaw := starknet.PadBytes(eventData[index].Big().Bytes(), MaxObservers) + observersRaw := starknet.PadBytes(eventData[index].BigInt(big.NewInt(0)).Bytes(), MaxObservers) // observation_len index++ - observationsLen := uint32(eventData[index].Big().Uint64()) + observationsLen := uint32(eventData[index].BigInt(big.NewInt(0)).Uint64()) // observers (based on observationsLen) var observers []uint8 @@ -92,31 +89,28 @@ func ParseNewTransmissionEvent(eventData []caigotypes.Felt) (NewTransmissionEven // observations (based on observationsLen) var observations []*big.Int for i := 0; i < int(observationsLen); i++ { - observations = append(observations, eventData[index+i+1].Big()) + observations = append(observations, eventData[index+i+1].BigInt(big.NewInt(0))) } // juels_per_fee_coin index += int(observationsLen) + 1 - juelsPerFeeCoin := eventData[index].Big() + juelsPerFeeCoin := eventData[index].BigInt(big.NewInt(0)) // juels_per_fee_coin index++ - gasPrice := eventData[index].Big() + gasPrice := eventData[index].BigInt(big.NewInt(0)) // config digest index++ - digest, err := types.BytesToConfigDigest(starknet.PadBytes(eventData[index].Bytes(), len(types.ConfigDigest{}))) - if err != nil { - return NewTransmissionEvent{}, errors.Wrap(err, "couldn't convert bytes to ConfigDigest") - } + digest := eventData[index].Bytes() // epoch_and_round index++ - epoch, round := parseEpochAndRound(eventData[index].Big()) + epoch, round := parseEpochAndRound(eventData[index].BigInt(big.NewInt(0))) // reimbursement index++ - reimbursement := eventData[index].Big() + reimbursement := eventData[index].BigInt(big.NewInt(0)) return NewTransmissionEvent{ RoundId: roundId, @@ -136,28 +130,28 @@ func ParseNewTransmissionEvent(eventData []caigotypes.Felt) (NewTransmissionEven } // ParseConfigSetEvent is decoding binary felt data as the libocr ContractConfig type -func ParseConfigSetEvent(eventData []caigotypes.Felt) (types.ContractConfig, error) { +func ParseConfigSetEvent(eventData []*felt.Felt) (types.ContractConfig, error) { { const oraclesLenIdx = 3 if len(eventData) < oraclesLenIdx { return types.ContractConfig{}, errors.New("invalid: event data") } - oraclesLen := eventData[oraclesLenIdx].Big().Uint64() + oraclesLen := eventData[oraclesLenIdx].BigInt(big.NewInt(0)).Uint64() onchainConfigLenIdx := oraclesLenIdx + 2*oraclesLen + 2 if uint64(len(eventData)) < onchainConfigLenIdx { return types.ContractConfig{}, errors.New("invalid: event data") } - onchainConfigLen := eventData[onchainConfigLenIdx].Big().Uint64() + onchainConfigLen := eventData[onchainConfigLenIdx].BigInt(big.NewInt(0)).Uint64() offchainConfigLenIdx := onchainConfigLenIdx + onchainConfigLen + 2 if uint64(len(eventData)) < offchainConfigLenIdx { return types.ContractConfig{}, errors.New("invalid: event data") } - offchainConfigLen := eventData[offchainConfigLenIdx].Big().Uint64() + offchainConfigLen := eventData[offchainConfigLenIdx].BigInt(big.NewInt(0)).Uint64() if uint64(len(eventData)) != offchainConfigLenIdx+offchainConfigLen+1 { return types.ContractConfig{}, errors.New("invalid: event data") } @@ -168,18 +162,15 @@ func ParseConfigSetEvent(eventData []caigotypes.Felt) (types.ContractConfig, err // latest_config_digest index++ - digest, err := types.BytesToConfigDigest(starknet.PadBytes(eventData[index].Bytes(), len(types.ConfigDigest{}))) - if err != nil { - return types.ContractConfig{}, errors.Wrap(err, "couldn't convert bytes to ConfigDigest") - } + digest := eventData[index].Bytes() // config_count index++ - configCount := eventData[index].Big().Uint64() + configCount := eventData[index].BigInt(big.NewInt(0)).Uint64() // oracles_len index++ - oraclesLen := eventData[index].Big().Uint64() + oraclesLen := eventData[index].BigInt(big.NewInt(0)).Uint64() // oracles index++ @@ -188,7 +179,8 @@ func ParseConfigSetEvent(eventData []caigotypes.Felt) (types.ContractConfig, err var transmitters []types.Account for i, member := range oracleMembers { if i%2 == 0 { - signers = append(signers, starknet.PadBytes(member.Bytes(), 32)) // pad to 32 bytes + b := member.Bytes() + signers = append(signers, b[:]) // pad to 32 bytes } else { transmitters = append(transmitters, types.Account(member.String())) } @@ -196,19 +188,19 @@ func ParseConfigSetEvent(eventData []caigotypes.Felt) (types.ContractConfig, err // f index = index + int(oraclesLen)*2 - f := eventData[index].Big().Uint64() + f := eventData[index].BigInt(big.NewInt(0)).Uint64() // onchain_config length index++ - onchainConfigLen := eventData[index].Big().Uint64() + onchainConfigLen := eventData[index].BigInt(big.NewInt(0)).Uint64() // onchain_config (version=1, min, max) index++ onchainConfigFelts := eventData[index:(index + int(onchainConfigLen))] onchainConfig, err := medianreport.OnchainConfigCodec{}.EncodeFromFelt( - onchainConfigFelts[0].Big(), - onchainConfigFelts[1].Big(), - onchainConfigFelts[2].Big(), + onchainConfigFelts[0].BigInt(big.NewInt(0)), + onchainConfigFelts[1].BigInt(big.NewInt(0)), + onchainConfigFelts[2].BigInt(big.NewInt(0)), ) if err != nil { return types.ContractConfig{}, errors.Wrap(err, "err in encoding onchain config from felts") @@ -216,11 +208,11 @@ func ParseConfigSetEvent(eventData []caigotypes.Felt) (types.ContractConfig, err // offchain_config_version index += int(onchainConfigLen) - offchainConfigVersion := eventData[index].Big().Uint64() + offchainConfigVersion := eventData[index].BigInt(big.NewInt(0)).Uint64() // offchain_config_len index++ - offchainConfigLen := eventData[index].Big().Uint64() + offchainConfigLen := eventData[index].BigInt(big.NewInt(0)).Uint64() // offchain_config index++ diff --git a/relayer/pkg/chainlink/ocr2/events_test.go b/relayer/pkg/chainlink/ocr2/events_test.go index 52f53590f..5ea442a22 100644 --- a/relayer/pkg/chainlink/ocr2/events_test.go +++ b/relayer/pkg/chainlink/ocr2/events_test.go @@ -9,7 +9,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - caigotypes "github.com/smartcontractkit/caigo/types" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -61,7 +62,7 @@ var ( ) func TestNewTransmissionEvent_Parse(t *testing.T) { - eventData, err := starknet.StringsToFelt(newTransmissionEventRaw) + eventData, err := starknetutils.HexArrToFelt(newTransmissionEventRaw) assert.NoError(t, err) require.Equal(t, len(newTransmissionEventRaw), len(eventData)) @@ -81,7 +82,8 @@ func TestNewTransmissionEvent_Parse(t *testing.T) { transmitterHex := "0x2c0dd77ce74b1667dc6fa782bbafaef5becbe2d04b052726ab236daeb52ac5d" require.Equal(t, len(transmitterHex), int(2+31.5*2)) // len('0x') + len(max_felt_len) - expectedTransmitter := caigotypes.StrToFelt(transmitterHex) + expectedTransmitter, err := starknetutils.HexToFelt(transmitterHex) + require.NoError(t, err) require.Equal(t, e.Transmitter, expectedTransmitter) require.Equal(t, e.Observers, []uint8{0, 1, 2, 3}) @@ -94,7 +96,7 @@ func TestNewTransmissionEvent_Parse(t *testing.T) { } func TestConfigSetEvent_Parse(t *testing.T) { - eventData, err := starknet.StringsToFelt(configSetEventRaw) + eventData, err := starknetutils.HexArrToFelt(configSetEventRaw) assert.NoError(t, err) require.Equal(t, len(configSetEventRaw), len(eventData)) @@ -144,7 +146,7 @@ func TestNewTransmissionEventSelector(t *testing.T) { require.NoError(t, err) eventKey := new(big.Int) eventKey.SetBytes(bytes) - assert.Equal(t, caigotypes.GetSelectorFromName("NewTransmission").Cmp(eventKey), 0) + assert.Equal(t, starknettypes.GetSelectorFromName("NewTransmission").Cmp(eventKey), 0) } func TestConfigSetEventSelector(t *testing.T) { @@ -152,5 +154,5 @@ func TestConfigSetEventSelector(t *testing.T) { require.NoError(t, err) eventKey := new(big.Int) eventKey.SetBytes(bytes) - assert.Equal(t, caigotypes.GetSelectorFromName("ConfigSet").Cmp(eventKey), 0) + assert.Equal(t, starknettypes.GetSelectorFromName("ConfigSet").Cmp(eventKey), 0) } diff --git a/relayer/pkg/chainlink/ocr2/medianreport/onchainconfig.go b/relayer/pkg/chainlink/ocr2/medianreport/onchainconfig.go index 4ea4a9f67..1f86e0555 100644 --- a/relayer/pkg/chainlink/ocr2/medianreport/onchainconfig.go +++ b/relayer/pkg/chainlink/ocr2/medianreport/onchainconfig.go @@ -4,10 +4,6 @@ import ( "fmt" "math/big" - "github.com/pkg/errors" - "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet" - - caigotypes "github.com/smartcontractkit/caigo/types" "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" ) @@ -52,17 +48,8 @@ func (codec OnchainConfigCodec) Decode(b []byte) (median.OnchainConfig, error) { return median.OnchainConfig{}, err } - // convert felts to big.Ints - - min, err := starknet.FeltToUnsignedBig(caigotypes.BigToFelt(felts[1])) - if err != nil { - return median.OnchainConfig{}, errors.Wrap(err, "min invalid") - } - - max, err := starknet.FeltToUnsignedBig(caigotypes.BigToFelt(felts[2])) - if err != nil { - return median.OnchainConfig{}, errors.Wrap(err, "max invalid") - } + min := felts[1] + max := felts[2] if !(min.Cmp(max) <= 0) { return median.OnchainConfig{}, fmt.Errorf("OnchainConfig min (%v) should not be greater than max(%v)", min, max) diff --git a/relayer/pkg/chainlink/ocr2/medianreport/report.go b/relayer/pkg/chainlink/ocr2/medianreport/report.go index 7049d8a6a..4edd36b0c 100644 --- a/relayer/pkg/chainlink/ocr2/medianreport/report.go +++ b/relayer/pkg/chainlink/ocr2/medianreport/report.go @@ -8,8 +8,9 @@ import ( "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" "github.com/pkg/errors" - caigotypes "github.com/smartcontractkit/caigo/types" "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -43,25 +44,37 @@ func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types // preserve original array oo = append([]median.ParsedAttributedObservation{}, oo...) - numFelt := caigotypes.BigToFelt(big.NewInt(int64(num))) + numFelt, err := starknetutils.BigIntToFelt(big.NewInt(int64(num))) + if err != nil { + return nil, fmt.Errorf("invalid felt: %v", err) + } // median timestamp sort.Slice(oo, func(i, j int) bool { return oo[i].Timestamp < oo[j].Timestamp }) timestamp := oo[num/2].Timestamp - timestampFelt := caigotypes.BigToFelt(big.NewInt(int64(timestamp))) + timestampFelt, err := starknetutils.BigIntToFelt(big.NewInt(int64(timestamp))) + if err != nil { + return nil, fmt.Errorf("invalid felt: %v", err) + } // median juelsPerFeeCoin sort.Slice(oo, func(i, j int) bool { return oo[i].JuelsPerFeeCoin.Cmp(oo[j].JuelsPerFeeCoin) < 0 }) juelsPerFeeCoin := oo[num/2].JuelsPerFeeCoin - juelsPerFeeCoinFelt := caigotypes.BigToFelt(juelsPerFeeCoin) + juelsPerFeeCoinFelt, err := starknetutils.BigIntToFelt(juelsPerFeeCoin) + if err != nil { + return nil, fmt.Errorf("invalid felt: %v", err) + } // TODO: source from observations gasPrice := big.NewInt(1) // := oo[num/2].GasPrice - gasPriceFelt := caigotypes.BigToFelt(gasPrice) + gasPriceFelt, err := starknetutils.BigIntToFelt(gasPrice) + if err != nil { + return nil, fmt.Errorf("invalid felt: %v", err) + } // sort by values sort.Slice(oo, func(i, j int) bool { @@ -69,21 +82,32 @@ func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types }) var observers = make([]byte, starknet.FeltLength) - var observations []caigotypes.Felt + var observations []*felt.Felt for i, o := range oo { observers[i] = byte(o.Observer) - observations = append(observations, caigotypes.BigToFelt(o.Value)) + + f, err := starknetutils.BigIntToFelt(o.Value) + if err != nil { + return nil, fmt.Errorf("invalid felt: %v", err) + } + observations = append(observations, f) } var report []byte - report = append(report, timestampFelt.Bytes()...) + + buf := timestampFelt.Bytes() + report = append(report, buf[:]...) report = append(report, observers...) - report = append(report, numFelt.Bytes()...) + buf = numFelt.Bytes() + report = append(report, buf[:]...) for _, o := range observations { - report = append(report, o.Bytes()...) + buf = o.Bytes() + report = append(report, buf[:]...) } - report = append(report, juelsPerFeeCoinFelt.Bytes()...) - report = append(report, gasPriceFelt.Bytes()...) + buf = juelsPerFeeCoinFelt.Bytes() + report = append(report, buf[:]...) + buf = gasPriceFelt.Bytes() + report = append(report, buf[:]...) return report, nil } @@ -95,7 +119,7 @@ func (c ReportCodec) MedianFromReport(report types.Report) (*big.Int, error) { } // Decode the number of observations - numBig := caigotypes.BytesToFelt(report[(timestampSizeBytes + observersSizeBytes):prefixSizeBytes]).Big() + numBig := new(felt.Felt).SetBytes(report[(timestampSizeBytes + observersSizeBytes):prefixSizeBytes]).BigInt(big.NewInt(0)) if !numBig.IsUint64() { return nil, errors.New("length of observations is invalid") } @@ -119,11 +143,8 @@ func (c ReportCodec) MedianFromReport(report types.Report) (*big.Int, error) { for i := 0; i < n; i++ { start := prefixSizeBytes + observationSizeBytes*i end := start + observationSizeBytes - obv := caigotypes.BytesToFelt(report[start:end]) - o, err := starknet.FeltToUnsignedBig(obv) - if err != nil { - return nil, errors.Wrap(err, "observation invalid") - } + obv := new(felt.Felt).SetBytes(report[start:end]) + o := obv.BigInt(big.NewInt(0)) oo = append(oo, o) } diff --git a/relayer/pkg/chainlink/ocr2/medianreport/report_test.go b/relayer/pkg/chainlink/ocr2/medianreport/report_test.go index c74355dd3..f86492926 100644 --- a/relayer/pkg/chainlink/ocr2/medianreport/report_test.go +++ b/relayer/pkg/chainlink/ocr2/medianreport/report_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - caigotypes "github.com/smartcontractkit/caigo/types" "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" ) @@ -71,7 +70,7 @@ func TestBuildReport(t *testing.T) { assert.Equal(t, totalLen, len(report), "validate length") // validate timestamp - timestamp := caigotypes.BytesToFelt(report[0:timestampSizeBytes]).Big() + timestamp := new(big.Int).SetBytes(report[0:timestampSizeBytes]) assert.Equal(t, uint64(oo[0].Timestamp), timestamp.Uint64(), "validate timestamp") // validate observers @@ -80,7 +79,7 @@ func TestBuildReport(t *testing.T) { // validate observer count index += observersSizeBytes - count := caigotypes.BytesToFelt(report[index : index+observationsLenBytes]).Big() + count := new(big.Int).SetBytes(report[index : index+observationsLenBytes]) assert.Equal(t, uint8(n), uint8(count.Uint64()), "validate observer count") // validate observations diff --git a/relayer/pkg/chainlink/ocr2/mocks/OCR2Reader.go b/relayer/pkg/chainlink/ocr2/mocks/OCR2Reader.go index 3da7aa9ce..ea85761de 100644 --- a/relayer/pkg/chainlink/ocr2/mocks/OCR2Reader.go +++ b/relayer/pkg/chainlink/ocr2/mocks/OCR2Reader.go @@ -6,13 +6,13 @@ import ( context "context" big "math/big" + felt "github.com/NethermindEth/juno/core/felt" + mock "github.com/stretchr/testify/mock" ocr2 "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2" starknet "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet" - - types "github.com/smartcontractkit/caigo/types" ) // OCR2Reader is an autogenerated mock type for the OCR2Reader type @@ -37,21 +37,21 @@ func (_m *OCR2Reader) BaseReader() starknet.Reader { } // BillingDetails provides a mock function with given fields: _a0, _a1 -func (_m *OCR2Reader) BillingDetails(_a0 context.Context, _a1 types.Felt) (ocr2.BillingDetails, error) { +func (_m *OCR2Reader) BillingDetails(_a0 context.Context, _a1 *felt.Felt) (ocr2.BillingDetails, error) { ret := _m.Called(_a0, _a1) var r0 ocr2.BillingDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (ocr2.BillingDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (ocr2.BillingDetails, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) ocr2.BillingDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) ocr2.BillingDetails); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(ocr2.BillingDetails) } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -61,21 +61,21 @@ func (_m *OCR2Reader) BillingDetails(_a0 context.Context, _a1 types.Felt) (ocr2. } // ConfigFromEventAt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *OCR2Reader) ConfigFromEventAt(_a0 context.Context, _a1 types.Felt, _a2 uint64) (ocr2.ContractConfig, error) { +func (_m *OCR2Reader) ConfigFromEventAt(_a0 context.Context, _a1 *felt.Felt, _a2 uint64) (ocr2.ContractConfig, error) { ret := _m.Called(_a0, _a1, _a2) var r0 ocr2.ContractConfig var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt, uint64) (ocr2.ContractConfig, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt, uint64) (ocr2.ContractConfig, error)); ok { return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt, uint64) ocr2.ContractConfig); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt, uint64) ocr2.ContractConfig); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Get(0).(ocr2.ContractConfig) } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt, uint64) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt, uint64) error); ok { r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) @@ -85,21 +85,21 @@ func (_m *OCR2Reader) ConfigFromEventAt(_a0 context.Context, _a1 types.Felt, _a2 } // LatestConfigDetails provides a mock function with given fields: _a0, _a1 -func (_m *OCR2Reader) LatestConfigDetails(_a0 context.Context, _a1 types.Felt) (ocr2.ContractConfigDetails, error) { +func (_m *OCR2Reader) LatestConfigDetails(_a0 context.Context, _a1 *felt.Felt) (ocr2.ContractConfigDetails, error) { ret := _m.Called(_a0, _a1) var r0 ocr2.ContractConfigDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (ocr2.ContractConfigDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (ocr2.ContractConfigDetails, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) ocr2.ContractConfigDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) ocr2.ContractConfigDetails); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(ocr2.ContractConfigDetails) } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -109,21 +109,21 @@ func (_m *OCR2Reader) LatestConfigDetails(_a0 context.Context, _a1 types.Felt) ( } // LatestRoundData provides a mock function with given fields: _a0, _a1 -func (_m *OCR2Reader) LatestRoundData(_a0 context.Context, _a1 types.Felt) (ocr2.RoundData, error) { +func (_m *OCR2Reader) LatestRoundData(_a0 context.Context, _a1 *felt.Felt) (ocr2.RoundData, error) { ret := _m.Called(_a0, _a1) var r0 ocr2.RoundData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (ocr2.RoundData, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (ocr2.RoundData, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) ocr2.RoundData); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) ocr2.RoundData); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(ocr2.RoundData) } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -133,21 +133,21 @@ func (_m *OCR2Reader) LatestRoundData(_a0 context.Context, _a1 types.Felt) (ocr2 } // LatestTransmissionDetails provides a mock function with given fields: _a0, _a1 -func (_m *OCR2Reader) LatestTransmissionDetails(_a0 context.Context, _a1 types.Felt) (ocr2.TransmissionDetails, error) { +func (_m *OCR2Reader) LatestTransmissionDetails(_a0 context.Context, _a1 *felt.Felt) (ocr2.TransmissionDetails, error) { ret := _m.Called(_a0, _a1) var r0 ocr2.TransmissionDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (ocr2.TransmissionDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (ocr2.TransmissionDetails, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) ocr2.TransmissionDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) ocr2.TransmissionDetails); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(ocr2.TransmissionDetails) } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -157,15 +157,15 @@ func (_m *OCR2Reader) LatestTransmissionDetails(_a0 context.Context, _a1 types.F } // LinkAvailableForPayment provides a mock function with given fields: _a0, _a1 -func (_m *OCR2Reader) LinkAvailableForPayment(_a0 context.Context, _a1 types.Felt) (*big.Int, error) { +func (_m *OCR2Reader) LinkAvailableForPayment(_a0 context.Context, _a1 *felt.Felt) (*big.Int, error) { ret := _m.Called(_a0, _a1) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (*big.Int, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (*big.Int, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) *big.Int); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) *big.Int); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { @@ -173,7 +173,7 @@ func (_m *OCR2Reader) LinkAvailableForPayment(_a0 context.Context, _a1 types.Fel } } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -183,15 +183,15 @@ func (_m *OCR2Reader) LinkAvailableForPayment(_a0 context.Context, _a1 types.Fel } // NewTransmissionsFromEventsAt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *OCR2Reader) NewTransmissionsFromEventsAt(_a0 context.Context, _a1 types.Felt, _a2 uint64) ([]ocr2.NewTransmissionEvent, error) { +func (_m *OCR2Reader) NewTransmissionsFromEventsAt(_a0 context.Context, _a1 *felt.Felt, _a2 uint64) ([]ocr2.NewTransmissionEvent, error) { ret := _m.Called(_a0, _a1, _a2) var r0 []ocr2.NewTransmissionEvent var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt, uint64) ([]ocr2.NewTransmissionEvent, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt, uint64) ([]ocr2.NewTransmissionEvent, error)); ok { return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt, uint64) []ocr2.NewTransmissionEvent); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt, uint64) []ocr2.NewTransmissionEvent); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { @@ -199,7 +199,7 @@ func (_m *OCR2Reader) NewTransmissionsFromEventsAt(_a0 context.Context, _a1 type } } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt, uint64) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt, uint64) error); ok { r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) diff --git a/relayer/pkg/chainlink/ocr2/types.go b/relayer/pkg/chainlink/ocr2/types.go index d81cf4f40..81b9b06e4 100644 --- a/relayer/pkg/chainlink/ocr2/types.go +++ b/relayer/pkg/chainlink/ocr2/types.go @@ -6,9 +6,7 @@ import ( "math/big" "time" - "github.com/pkg/errors" - - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "github.com/smartcontractkit/libocr/offchainreporting2/types" ) @@ -17,12 +15,7 @@ type ContractConfigDetails struct { Digest types.ConfigDigest } -func NewContractConfigDetails(blockNum *big.Int, digestBytes []byte) (ccd ContractConfigDetails, err error) { - digest, err := types.BytesToConfigDigest(digestBytes) - if err != nil { - return ccd, errors.Wrap(err, "couldn't decode config digest") - } - +func NewContractConfigDetails(blockNum *big.Int, digest [32]byte) (ccd ContractConfigDetails, err error) { return ContractConfigDetails{ Block: blockNum.Uint64(), Digest: digest, @@ -62,26 +55,27 @@ type RoundData struct { UpdatedAt time.Time } -func NewRoundData(felts []caigotypes.Felt) (data RoundData, err error) { +func NewRoundData(felts []*felt.Felt) (data RoundData, err error) { if len(felts) != 5 { return data, fmt.Errorf("expected number of felts to be 5 but got %d", len(felts)) } - if !felts[0].Big().IsUint64() && felts[0].Big().Uint64() > math.MaxUint32 { - return data, fmt.Errorf("aggregator round id does not fit in a uint32 '%s'", felts[0].Big()) + roundId := felts[0].BigInt(big.NewInt(0)) + if !roundId.IsUint64() && roundId.Uint64() > math.MaxUint32 { + return data, fmt.Errorf("aggregator round id does not fit in a uint32 '%s'", felts[0].String()) } - data.RoundID = uint32(felts[0].Big().Uint64()) - data.Answer = felts[1].Big() - blockNumber := felts[2].Big() + data.RoundID = uint32(roundId.Uint64()) + data.Answer = felts[1].BigInt(big.NewInt(0)) + blockNumber := felts[2].BigInt(big.NewInt(0)) if !blockNumber.IsUint64() { return data, fmt.Errorf("block number '%s' does not fit into uint64", blockNumber.String()) } data.BlockNumber = blockNumber.Uint64() - startedAt := felts[3].Big() + startedAt := felts[3].BigInt(big.NewInt(0)) if !startedAt.IsInt64() { return data, fmt.Errorf("startedAt '%s' does not fit into int64", startedAt.String()) } data.StartedAt = time.Unix(startedAt.Int64(), 0) - updatedAt := felts[4].Big() + updatedAt := felts[4].BigInt(big.NewInt(0)) if !updatedAt.IsInt64() { return data, fmt.Errorf("updatedAt '%s' does not fit into int64", startedAt.String()) } diff --git a/relayer/pkg/chainlink/ocr2/types_test.go b/relayer/pkg/chainlink/ocr2/types_test.go index 8d339f56c..3c30b9d1d 100644 --- a/relayer/pkg/chainlink/ocr2/types_test.go +++ b/relayer/pkg/chainlink/ocr2/types_test.go @@ -5,18 +5,10 @@ import ( "testing" "time" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/require" ) -func StringsToCaigoFelts(in []string) []caigotypes.Felt { - out := make([]caigotypes.Felt, len(in)) - for i := 0; i < len(in); i++ { - out[i] = caigotypes.StrToFelt(in[i]) - } - return out -} - func TestNewRoundData(t *testing.T) { raw := []string{ "0x121e", @@ -26,7 +18,8 @@ func TestNewRoundData(t *testing.T) { "0x633344a5", } - felts := StringsToCaigoFelts(raw) + felts, err := starknetutils.HexArrToFelt(raw) + require.NoError(t, err) actualRound, err := NewRoundData(felts) require.NoError(t, err) expectedRound := RoundData{ diff --git a/relayer/pkg/chainlink/txm/keystore.go b/relayer/pkg/chainlink/txm/keystore.go index 6881ac77d..196cf13e2 100644 --- a/relayer/pkg/chainlink/txm/keystore.go +++ b/relayer/pkg/chainlink/txm/keystore.go @@ -6,7 +6,7 @@ import ( "fmt" "math/big" - "github.com/smartcontractkit/caigo" + "github.com/NethermindEth/starknet.go" "github.com/smartcontractkit/chainlink-relay/pkg/loop" adapters "github.com/smartcontractkit/chainlink-relay/pkg/loop/adapters/starknet" @@ -15,7 +15,7 @@ import ( // KeystoreAdapter is a starknet-specific adaption layer to translate between the generic Loop Keystore (bytes) and // the type specific caigo Keystore (big.Int) type KeystoreAdapter interface { - caigo.Keystore + starknetgo.Keystore Loopp() loop.Keystore } diff --git a/relayer/pkg/chainlink/txm/mocks/nonce_manager_client.go b/relayer/pkg/chainlink/txm/mocks/nonce_manager_client.go index 8e49300a0..076ee279e 100644 --- a/relayer/pkg/chainlink/txm/mocks/nonce_manager_client.go +++ b/relayer/pkg/chainlink/txm/mocks/nonce_manager_client.go @@ -6,9 +6,9 @@ import ( context "context" big "math/big" - mock "github.com/stretchr/testify/mock" + felt "github.com/NethermindEth/juno/core/felt" - types "github.com/smartcontractkit/caigo/types" + mock "github.com/stretchr/testify/mock" ) // NonceManagerClient is an autogenerated mock type for the NonceManagerClient type @@ -17,15 +17,15 @@ type NonceManagerClient struct { } // AccountNonce provides a mock function with given fields: _a0, _a1 -func (_m *NonceManagerClient) AccountNonce(_a0 context.Context, _a1 types.Felt) (*big.Int, error) { +func (_m *NonceManagerClient) AccountNonce(_a0 context.Context, _a1 *felt.Felt) (*big.Int, error) { ret := _m.Called(_a0, _a1) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (*big.Int, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (*big.Int, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) *big.Int); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) *big.Int); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { @@ -33,7 +33,7 @@ func (_m *NonceManagerClient) AccountNonce(_a0 context.Context, _a1 types.Felt) } } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) diff --git a/relayer/pkg/chainlink/txm/nonce.go b/relayer/pkg/chainlink/txm/nonce.go index c2626664c..eb540658c 100644 --- a/relayer/pkg/chainlink/txm/nonce.go +++ b/relayer/pkg/chainlink/txm/nonce.go @@ -6,7 +6,7 @@ import ( "math/big" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink-relay/pkg/types" @@ -16,16 +16,16 @@ import ( //go:generate mockery --name NonceManagerClient --output ./mocks/ --case=underscore --filename nonce_manager_client.go type NonceManagerClient interface { - AccountNonce(context.Context, caigotypes.Felt) (*big.Int, error) + AccountNonce(context.Context, *felt.Felt) (*big.Int, error) } type NonceManager interface { types.Service - Register(ctx context.Context, address caigotypes.Felt, chainId string, client NonceManagerClient) error + Register(ctx context.Context, address *felt.Felt, chainId string, client NonceManagerClient) error - NextSequence(address caigotypes.Felt, chainID string) (*big.Int, error) - IncrementNextSequence(address caigotypes.Felt, chainID string, currentNonce *big.Int) error + NextSequence(address *felt.Felt, chainID string) (*big.Int, error) + IncrementNextSequence(address *felt.Felt, chainID string, currentNonce *big.Int) error } var _ NonceManager = (*nonceManager)(nil) @@ -66,7 +66,7 @@ func (nm *nonceManager) HealthReport() map[string]error { } // Register is used because we cannot pre-fetch nonces. the pubkey is known before hand, but the account address is not known until a job is started and sends a tx -func (nm *nonceManager) Register(ctx context.Context, addr caigotypes.Felt, chainId string, client NonceManagerClient) error { +func (nm *nonceManager) Register(ctx context.Context, addr *felt.Felt, chainId string, client NonceManagerClient) error { nm.lock.Lock() defer nm.lock.Unlock() addressNonces, exists := nm.n[addr.String()] @@ -85,7 +85,7 @@ func (nm *nonceManager) Register(ctx context.Context, addr caigotypes.Felt, chai return nil } -func (nm *nonceManager) NextSequence(addr caigotypes.Felt, chainId string) (*big.Int, error) { +func (nm *nonceManager) NextSequence(addr *felt.Felt, chainId string) (*big.Int, error) { if err := nm.validate(addr, chainId); err != nil { return nil, err } @@ -95,7 +95,7 @@ func (nm *nonceManager) NextSequence(addr caigotypes.Felt, chainId string) (*big return nm.n[addr.String()][chainId], nil } -func (nm *nonceManager) IncrementNextSequence(addr caigotypes.Felt, chainId string, currentNonce *big.Int) error { +func (nm *nonceManager) IncrementNextSequence(addr *felt.Felt, chainId string, currentNonce *big.Int) error { if err := nm.validate(addr, chainId); err != nil { return err } @@ -110,7 +110,7 @@ func (nm *nonceManager) IncrementNextSequence(addr caigotypes.Felt, chainId stri return nil } -func (nm *nonceManager) validate(addr caigotypes.Felt, id string) error { +func (nm *nonceManager) validate(addr *felt.Felt, id string) error { nm.lock.RLock() defer nm.lock.RUnlock() if _, exists := nm.n[addr.String()]; !exists { diff --git a/relayer/pkg/chainlink/txm/nonce_test.go b/relayer/pkg/chainlink/txm/nonce_test.go index 7dc2dde7c..ec16e4418 100644 --- a/relayer/pkg/chainlink/txm/nonce_test.go +++ b/relayer/pkg/chainlink/txm/nonce_test.go @@ -5,7 +5,8 @@ import ( "math/big" "testing" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" + "github.com/NethermindEth/juno/core/felt" "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink-relay/pkg/utils" @@ -18,14 +19,15 @@ import ( "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/txm/mocks" ) -func newTestNonceManager(t *testing.T, chainID string, initNonce *big.Int) (txm.NonceManager, caigotypes.Felt, func()) { +func newTestNonceManager(t *testing.T, chainID string, initNonce *big.Int) (txm.NonceManager, *felt.Felt, func()) { // setup c := mocks.NewNonceManagerClient(t) lggr := logger.Test(t) nm := txm.NewNonceManager(lggr) // mock returns - keyHash := caigotypes.StrToFelt("test-key-id") + keyHash, err := starknetutils.HexToFelt("0x0") + require.NoError(t, err) c.On("AccountNonce", mock.Anything, mock.Anything).Return(initNonce, nil).Once() require.NoError(t, nm.Start(utils.Context(t))) @@ -53,7 +55,8 @@ func TestNonceManager_NextSequence(t *testing.T) { assert.Contains(t, err.Error(), fmt.Sprintf("nonce does not exist for key: %s and chain: %s", k.String(), "invalid_chainId")) // should fail with invalid address - randAddr1 := caigotypes.BigToFelt(big.NewInt(1)) + randAddr1, err := starknetutils.BigIntToFelt(big.NewInt(1)) + require.NoError(t, err) _, err = nm.NextSequence(randAddr1, chainId) require.Error(t, err) assert.Contains(t, err.Error(), fmt.Sprintf("nonce tracking does not exist for key: %s", randAddr1.String())) @@ -88,7 +91,8 @@ func TestNonceManager_IncrementNextSequence(t *testing.T) { assert.Contains(t, err.Error(), fmt.Sprintf("nonce does not exist for key: %s and chain: %s", k.String(), "invalid_chainId")) // should fail with invalid address - randAddr1 := caigotypes.BigToFelt(big.NewInt(1)) + randAddr1, err := starknetutils.BigIntToFelt(big.NewInt(1)) + require.NoError(t, err) err = nm.IncrementNextSequence(randAddr1, chainId, initPlusOne) require.Error(t, err) assert.Contains(t, err.Error(), fmt.Sprintf("nonce tracking does not exist for key: %s", randAddr1.String())) diff --git a/relayer/pkg/chainlink/txm/test_helpers.go b/relayer/pkg/chainlink/txm/test_helpers.go index 3c9d5fa02..5cc8ed2b5 100644 --- a/relayer/pkg/chainlink/txm/test_helpers.go +++ b/relayer/pkg/chainlink/txm/test_helpers.go @@ -7,7 +7,7 @@ import ( "testing" "time" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -76,9 +76,9 @@ func TestKeys(t *testing.T, count int) (rawkeys [][]byte) { if i >= count { break } - - keyBytes := caigotypes.StrToFelt(k).Bytes() - rawkeys = append(rawkeys, keyBytes) + f, _ := starknetutils.HexToFelt(k) + keyBytes := f.Bytes() + rawkeys = append(rawkeys, keyBytes[:]) } return rawkeys } diff --git a/relayer/pkg/chainlink/txm/txm.go b/relayer/pkg/chainlink/txm/txm.go index c1bab0c18..a4172b5f1 100644 --- a/relayer/pkg/chainlink/txm/txm.go +++ b/relayer/pkg/chainlink/txm/txm.go @@ -9,9 +9,11 @@ import ( "sync" "time" - "github.com/smartcontractkit/caigo" - caigorpc "github.com/smartcontractkit/caigo/rpcv02" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" + "github.com/NethermindEth/starknet.go" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink-relay/pkg/logger" @@ -26,14 +28,14 @@ const ( ) type TxManager interface { - Enqueue(senderAddress caigotypes.Felt, accountAddress caigotypes.Felt, txFn caigotypes.FunctionCall) error + Enqueue(senderAddress *felt.Felt, accountAddress *felt.Felt, txFn starknettypes.FunctionCall) error InflightCount() (int, int) } type Tx struct { - senderAddress caigotypes.Felt - accountAddress caigotypes.Felt - call caigotypes.FunctionCall + senderAddress *felt.Felt + accountAddress *felt.Felt + call starknettypes.FunctionCall } type StarkTXM interface { @@ -125,15 +127,15 @@ func (txm *starktxm) broadcastLoop() { const FEE_MARGIN uint64 = 115 -func (txm *starktxm) broadcast(ctx context.Context, senderAddress caigotypes.Felt, accountAddress caigotypes.Felt, tx caigotypes.FunctionCall) (txhash string, err error) { - txs := []caigotypes.FunctionCall{tx} +func (txm *starktxm) broadcast(ctx context.Context, senderAddress *felt.Felt, accountAddress *felt.Felt, tx starknettypes.FunctionCall) (txhash string, err error) { + txs := []starknettypes.FunctionCall{tx} client, err := txm.client.Get() if err != nil { txm.client.Reset() return txhash, fmt.Errorf("broadcast: failed to fetch client: %+w", err) } // create new account - account, err := caigo.NewRPCAccount(senderAddress, accountAddress, txm.ks, client.Provider, caigo.AccountVersion1) + account, err := starknetgo.NewRPCAccount(senderAddress, accountAddress, txm.ks, client.Provider, starknetgo.AccountVersion1) if err != nil { return txhash, fmt.Errorf("failed to create new account: %+w", err) } @@ -151,7 +153,7 @@ func (txm *starktxm) broadcast(ctx context.Context, senderAddress caigotypes.Fel // get fee for txm // optional - pass nonce to fee estimate (if nonce gets ahead, estimate may fail) // can we estimate fee without calling estimate - tbd with 1.0 - feeEstimate, err := account.EstimateFee(ctx, txs, caigotypes.ExecuteDetails{}) + feeEstimate, err := account.EstimateFee(ctx, txs, starknettypes.ExecuteDetails{}) if err != nil { return txhash, fmt.Errorf("failed to estimate fee: %+w", err) } @@ -159,7 +161,7 @@ func (txm *starktxm) broadcast(ctx context.Context, senderAddress caigotypes.Fel fee, _ := big.NewInt(0).SetString(string(feeEstimate.OverallFee), 0) expandedFee := big.NewInt(0).Mul(fee, big.NewInt(int64(FEE_MARGIN))) max := big.NewInt(0).Div(expandedFee, big.NewInt(100)) - details := caigotypes.ExecuteDetails{ + details := starknettypes.ExecuteDetails{ MaxFee: max, Nonce: nonce, } @@ -179,11 +181,12 @@ func (txm *starktxm) broadcast(ctx context.Context, senderAddress caigotypes.Fel } // update nonce if transaction is successful + hash := res.TransactionHash.String() err = errors.Join( txm.nonce.IncrementNextSequence(accountAddress, chainID, nonce), - txm.txStore.Save(accountAddress, nonce, res.TransactionHash), + txm.txStore.Save(accountAddress, nonce, hash), ) - return res.TransactionHash, err + return hash, err } func (txm *starktxm) confirmLoop() { @@ -210,12 +213,17 @@ func (txm *starktxm) confirmLoop() { for addr := range hashes { for i := range hashes[addr] { hash := hashes[addr][i] - response, err := client.Provider.TransactionReceipt(ctx, caigotypes.StrToFelt(hashes[addr][i])) + f, err := starknetutils.HexToFelt(hash) + if err != nil { + txm.lggr.Errorw("invalid felt value", "hash", hash) + continue + } + response, err := client.Provider.TransactionReceipt(ctx, f) if err != nil { txm.lggr.Errorw("failed to fetch transaction status", "hash", hash, "error", err) continue } - receipt, ok := response.(caigorpc.InvokeTransactionReceipt) + receipt, ok := response.(starknetrpc.InvokeTransactionReceipt) if !ok { txm.lggr.Errorw("wrong receipt type", "type", reflect.TypeOf(response)) continue @@ -223,7 +231,7 @@ func (txm *starktxm) confirmLoop() { status := receipt.Status - if status == caigotypes.TransactionAcceptedOnL1 || status == caigotypes.TransactionAcceptedOnL2 || status == caigotypes.TransactionRejected { + if status == starknetrpc.TransactionAcceptedOnL1 || status == starknetrpc.TransactionAcceptedOnL2 || status == starknetrpc.TransactionRejected { txm.lggr.Debugw(fmt.Sprintf("tx confirmed: %s", status), "hash", hash, "status", status) if err := txm.txStore.Confirm(addr, hash); err != nil { txm.lggr.Errorw("failed to confirm tx in TxStore", "hash", hash, "sender", addr, "error", err) @@ -260,7 +268,7 @@ func (txm *starktxm) HealthReport() map[string]error { return map[string]error{txm.Name(): txm.Healthy()} } -func (txm *starktxm) Enqueue(senderAddress, accountAddress caigotypes.Felt, tx caigotypes.FunctionCall) error { +func (txm *starktxm) Enqueue(senderAddress, accountAddress *felt.Felt, tx starknettypes.FunctionCall) error { // validate key exists for sender // use the embedded Loopp Keystore to do this; the spec and design // encourage passing nil data to the loop.Keystore.Sign as way to test diff --git a/relayer/pkg/chainlink/txm/txm_test.go b/relayer/pkg/chainlink/txm/txm_test.go index c74e88c49..a0788c4ab 100644 --- a/relayer/pkg/chainlink/txm/txm_test.go +++ b/relayer/pkg/chainlink/txm/txm_test.go @@ -9,10 +9,11 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo" - caigogw "github.com/smartcontractkit/caigo/gateway" - "github.com/smartcontractkit/caigo/test" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/starknet.go" + starknetgw "github.com/NethermindEth/starknet.go/gateway" + "github.com/NethermindEth/starknet.go/test" + starknettypes "github.com/NethermindEth/starknet.go/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" @@ -35,25 +36,26 @@ func TestIntegration_Txm(t *testing.T) { localKeys := map[string]*big.Int{} localAccounts := map[string]string{} for i := range accounts { - privKey, err := caigotypes.HexToBytes(accounts[i].PrivateKey) + privKey, err := starknettypes.HexToBytes(accounts[i].PrivateKey) require.NoError(t, err) - senderAddress := caigotypes.StrToFelt(accounts[i].PublicKey).String() - localKeys[senderAddress] = caigotypes.BytesToBig(privKey) - localAccounts[senderAddress] = accounts[i].Address + senderAddress, err := starknetutils.HexToFelt(accounts[i].PublicKey) + require.NoError(t, err) + localKeys[senderAddress.String()] = starknettypes.BytesToBig(privKey) + localAccounts[senderAddress.String()] = accounts[i].Address } // mock keystore looppKs := NewLooppKeystore(func(id string) (*big.Int, error) { - _, ok := localKeys[id] + key, ok := localKeys[id] if !ok { return nil, fmt.Errorf("key does not exist id=%s", id) } - return localKeys[id], nil + return key, nil }) ksAdapter := NewKeystoreAdapter(looppKs) lggr, observer := logger.TestObserved(t, zapcore.DebugLevel) timeout := 10 * time.Second - client, err := starknet.NewClient(caigogw.GOERLI_ID, url+"/rpc", lggr, &timeout) + client, err := starknet.NewClient(starknetgw.GOERLI_ID, url+"/rpc", lggr, &timeout) require.NoError(t, err) getClient := func() (*starknet.Client, error) { @@ -76,11 +78,21 @@ func TestIntegration_Txm(t *testing.T) { require.NoError(t, txm.Ready()) for senderAddressStr := range localKeys { - senderAddress := caigotypes.StrToFelt(senderAddressStr) + senderAddress, err := starknetutils.HexToFelt(senderAddressStr) + require.NoError(t, err) + + account, err := starknetutils.HexToFelt(localAccounts[senderAddressStr]) + require.NoError(t, err) + + contractAddress, err := starknetutils.HexToFelt("0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7") + require.NoError(t, err) + + selector := starknettypes.GetSelectorFromNameFelt("totalSupply") + for i := 0; i < n; i++ { - require.NoError(t, txm.Enqueue(senderAddress, caigotypes.StrToFelt(localAccounts[senderAddressStr]), caigotypes.FunctionCall{ - ContractAddress: caigotypes.StrToFelt("0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"), // send to ETH token contract - EntryPointSelector: "totalSupply", + require.NoError(t, txm.Enqueue(senderAddress, account, starknettypes.FunctionCall{ + ContractAddress: contractAddress, // send to ETH token contract + EntryPointSelector: selector, })) } } @@ -135,7 +147,7 @@ func (lk *LooppKeystore) Sign(ctx context.Context, id string, hash []byte) ([]by } starkHash := new(big.Int).SetBytes(hash) - x, y, err := caigo.Curve.Sign(starkHash, k) + x, y, err := starknetgo.Curve.Sign(starkHash, k) if err != nil { return nil, fmt.Errorf("error signing data with curve: %w", err) } diff --git a/relayer/pkg/chainlink/txm/txstore.go b/relayer/pkg/chainlink/txm/txstore.go index 4c2c2b5f6..ce47b9de9 100644 --- a/relayer/pkg/chainlink/txm/txstore.go +++ b/relayer/pkg/chainlink/txm/txstore.go @@ -5,7 +5,7 @@ import ( "math/big" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "golang.org/x/exp/maps" ) @@ -77,17 +77,17 @@ func (s *TxStore) InflightCount() int { } type ChainTxStore struct { - store map[caigotypes.Felt]*TxStore + store map[*felt.Felt]*TxStore lock sync.RWMutex } func NewChainTxStore() *ChainTxStore { return &ChainTxStore{ - store: map[caigotypes.Felt]*TxStore{}, + store: map[*felt.Felt]*TxStore{}, } } -func (c *ChainTxStore) Save(from caigotypes.Felt, nonce *big.Int, hash string) error { +func (c *ChainTxStore) Save(from *felt.Felt, nonce *big.Int, hash string) error { // use write lock for methods that modify underlying data c.lock.Lock() defer c.lock.Unlock() @@ -98,7 +98,7 @@ func (c *ChainTxStore) Save(from caigotypes.Felt, nonce *big.Int, hash string) e return c.store[from].Save(nonce, hash) } -func (c *ChainTxStore) Confirm(from caigotypes.Felt, hash string) error { +func (c *ChainTxStore) Confirm(from *felt.Felt, hash string) error { // use write lock for methods that modify underlying data c.lock.Lock() defer c.lock.Unlock() @@ -109,12 +109,12 @@ func (c *ChainTxStore) Confirm(from caigotypes.Felt, hash string) error { return c.store[from].Confirm(hash) } -func (c *ChainTxStore) GetAllInflightCount() map[caigotypes.Felt]int { +func (c *ChainTxStore) GetAllInflightCount() map[*felt.Felt]int { // use read lock for methods that read underlying data c.lock.RLock() defer c.lock.RUnlock() - list := map[caigotypes.Felt]int{} + list := map[*felt.Felt]int{} for i := range c.store { list[i] = c.store[i].InflightCount() @@ -123,12 +123,12 @@ func (c *ChainTxStore) GetAllInflightCount() map[caigotypes.Felt]int { return list } -func (c *ChainTxStore) GetAllUnconfirmed() map[caigotypes.Felt][]string { +func (c *ChainTxStore) GetAllUnconfirmed() map[*felt.Felt][]string { // use read lock for methods that read underlying data c.lock.RLock() defer c.lock.RUnlock() - list := map[caigotypes.Felt][]string{} + list := map[*felt.Felt][]string{} for i := range c.store { list[i] = c.store[i].GetUnconfirmed() @@ -136,7 +136,7 @@ func (c *ChainTxStore) GetAllUnconfirmed() map[caigotypes.Felt][]string { return list } -func (c *ChainTxStore) validate(from caigotypes.Felt) error { +func (c *ChainTxStore) validate(from *felt.Felt) error { if _, exists := c.store[from]; !exists { return fmt.Errorf("from address does not exist: %s", from) } diff --git a/relayer/pkg/chainlink/txm/txstore_test.go b/relayer/pkg/chainlink/txm/txstore_test.go index dd415952f..b87eb8243 100644 --- a/relayer/pkg/chainlink/txm/txstore_test.go +++ b/relayer/pkg/chainlink/txm/txstore_test.go @@ -7,7 +7,7 @@ import ( "sync" "testing" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -131,36 +131,41 @@ func TestChainTxStore(t *testing.T) { c := NewChainTxStore() + felt, err := starknetutils.BigIntToFelt(big.NewInt(0)) + require.NoError(t, err) + felt1, err := starknetutils.BigIntToFelt(big.NewInt(1)) + require.NoError(t, err) + // automatically save the from address - require.NoError(t, c.Save(caigotypes.Felt{}, big.NewInt(0), "0x0")) + require.NoError(t, c.Save(felt, big.NewInt(0), "0x0")) // reject saving for existing address and reused hash & nonce // error messages are tested within TestTxStore - assert.Error(t, c.Save(caigotypes.Felt{}, big.NewInt(0), "0x1")) - assert.Error(t, c.Save(caigotypes.Felt{}, big.NewInt(1), "0x0")) + assert.Error(t, c.Save(felt, big.NewInt(0), "0x1")) + assert.Error(t, c.Save(felt, big.NewInt(1), "0x0")) // inflight count - count, exists := c.GetAllInflightCount()[caigotypes.Felt{}] + count, exists := c.GetAllInflightCount()[felt] require.True(t, exists) assert.Equal(t, 1, count) - _, exists = c.GetAllInflightCount()[caigotypes.BigToFelt(big.NewInt(1))] + _, exists = c.GetAllInflightCount()[felt1] require.False(t, exists) // get unconfirmed list := c.GetAllUnconfirmed() assert.Equal(t, 1, len(list)) - hashes, ok := list[caigotypes.Felt{}] + hashes, ok := list[felt] assert.True(t, ok) assert.Equal(t, []string{"0x0"}, hashes) // confirm - assert.NoError(t, c.Confirm(caigotypes.Felt{}, "0x0")) - assert.ErrorContains(t, c.Confirm(caigotypes.BigToFelt(big.NewInt(1)), "0x0"), "from address does not exist") - assert.Error(t, c.Confirm(caigotypes.Felt{}, "0x1")) + assert.NoError(t, c.Confirm(felt, "0x0")) + assert.ErrorContains(t, c.Confirm(felt1, "0x0"), "from address does not exist") + assert.Error(t, c.Confirm(felt, "0x1")) list = c.GetAllUnconfirmed() assert.Equal(t, 1, len(list)) - assert.Equal(t, 0, len(list[caigotypes.Felt{}])) - count, exists = c.GetAllInflightCount()[caigotypes.Felt{}] + assert.Equal(t, 0, len(list[felt])) + count, exists = c.GetAllInflightCount()[felt] assert.True(t, exists) assert.Equal(t, 0, count) } diff --git a/relayer/pkg/starknet/client.go b/relayer/pkg/starknet/client.go index 34da24102..c743aa210 100644 --- a/relayer/pkg/starknet/client.go +++ b/relayer/pkg/starknet/client.go @@ -7,10 +7,11 @@ import ( "github.com/pkg/errors" + "github.com/NethermindEth/juno/core/felt" + caigo "github.com/NethermindEth/starknet.go" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" + starknetutils "github.com/NethermindEth/starknet.go/utils" ethrpc "github.com/ethereum/go-ethereum/rpc" - caigo "github.com/smartcontractkit/caigo" - caigorpc "github.com/smartcontractkit/caigo/rpcv02" - caigotypes "github.com/smartcontractkit/caigo/types" "github.com/smartcontractkit/chainlink-relay/pkg/logger" ) @@ -18,16 +19,16 @@ import ( //go:generate mockery --name Reader --output ./mocks/ type Reader interface { - CallContract(context.Context, CallOps) ([]string, error) + CallContract(context.Context, CallOps) ([]*felt.Felt, error) LatestBlockHeight(context.Context) (uint64, error) // provider interface - BlockWithTxHashes(ctx context.Context, blockID caigorpc.BlockID) (*caigorpc.Block, error) - Call(context.Context, caigotypes.FunctionCall, caigorpc.BlockID) ([]string, error) - Events(ctx context.Context, input caigorpc.EventsInput) (*caigorpc.EventsOutput, error) - TransactionByHash(context.Context, caigotypes.Felt) (caigorpc.Transaction, error) - TransactionReceipt(context.Context, caigotypes.Felt) (caigorpc.TransactionReceipt, error) - AccountNonce(context.Context, caigotypes.Felt) (*big.Int, error) + BlockWithTxHashes(ctx context.Context, blockID starknetrpc.BlockID) (*starknetrpc.Block, error) + Call(context.Context, starknetrpc.FunctionCall, starknetrpc.BlockID) ([]*felt.Felt, error) + Events(ctx context.Context, input starknetrpc.EventsInput) (*starknetrpc.EventChunk, error) + TransactionByHash(context.Context, *felt.Felt) (starknetrpc.Transaction, error) + TransactionReceipt(context.Context, *felt.Felt) (starknetrpc.TransactionReceipt, error) + AccountNonce(context.Context, *felt.Felt) (*big.Int, error) } type Writer interface { @@ -40,10 +41,10 @@ type ReaderWriter interface { var _ ReaderWriter = (*Client)(nil) -// var _ caigotypes.Provider = (*Client)(nil) +// var _ starknettypes.Provider = (*Client)(nil) type Client struct { - Provider *caigorpc.Provider + Provider *starknetrpc.Provider lggr logger.Logger defaultTimeout time.Duration } @@ -57,7 +58,7 @@ func NewClient(_chainID string, baseURL string, lggr logger.Logger, timeout *tim } client := &Client{ - Provider: caigorpc.NewProvider(c), + Provider: starknetrpc.NewProvider(c), lggr: lggr, } @@ -74,19 +75,19 @@ func NewClient(_chainID string, baseURL string, lggr logger.Logger, timeout *tim // -- Custom Wrapped Func -- -func (c *Client) CallContract(ctx context.Context, ops CallOps) (res []string, err error) { - tx := caigotypes.FunctionCall{ +func (c *Client) CallContract(ctx context.Context, ops CallOps) (data []*felt.Felt, err error) { + tx := starknetrpc.FunctionCall{ ContractAddress: ops.ContractAddress, EntryPointSelector: ops.Selector, Calldata: ops.Calldata, } - res, err = c.Call(ctx, tx, caigorpc.WithBlockTag("pending")) + res, err := c.Call(ctx, tx, starknetrpc.WithBlockTag("pending")) if err != nil { - return res, errors.Wrap(err, "error in client.CallContract") + return nil, errors.Wrap(err, "error in client.CallContract") } - return + return res, nil } func (c *Client) LatestBlockHeight(ctx context.Context) (height uint64, err error) { @@ -106,7 +107,7 @@ func (c *Client) LatestBlockHeight(ctx context.Context) (height uint64, err erro // -- caigo.Provider interface -- -func (c *Client) BlockWithTxHashes(ctx context.Context, blockID caigorpc.BlockID) (*caigorpc.Block, error) { +func (c *Client) BlockWithTxHashes(ctx context.Context, blockID starknetrpc.BlockID) (*starknetrpc.Block, error) { if c.defaultTimeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.defaultTimeout) @@ -115,12 +116,12 @@ func (c *Client) BlockWithTxHashes(ctx context.Context, blockID caigorpc.BlockID out, err := c.Provider.BlockWithTxHashes(ctx, blockID) if err != nil { - return out.(*caigorpc.Block), errors.Wrap(err, "error in client.BlockWithTxHashes") + return out.(*starknetrpc.Block), errors.Wrap(err, "error in client.BlockWithTxHashes") } - return out.(*caigorpc.Block), nil + return out.(*starknetrpc.Block), nil } -func (c *Client) Call(ctx context.Context, calls caigotypes.FunctionCall, blockHashOrTag caigorpc.BlockID) ([]string, error) { +func (c *Client) Call(ctx context.Context, calls starknetrpc.FunctionCall, blockHashOrTag starknetrpc.BlockID) ([]*felt.Felt, error) { if c.defaultTimeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.defaultTimeout) @@ -138,7 +139,7 @@ func (c *Client) Call(ctx context.Context, calls caigotypes.FunctionCall, blockH } -func (c *Client) TransactionByHash(ctx context.Context, hash caigotypes.Felt) (caigorpc.Transaction, error) { +func (c *Client) TransactionByHash(ctx context.Context, hash *felt.Felt) (starknetrpc.Transaction, error) { if c.defaultTimeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.defaultTimeout) @@ -156,7 +157,7 @@ func (c *Client) TransactionByHash(ctx context.Context, hash caigotypes.Felt) (c } -func (c *Client) TransactionReceipt(ctx context.Context, hash caigotypes.Felt) (caigorpc.TransactionReceipt, error) { +func (c *Client) TransactionReceipt(ctx context.Context, hash *felt.Felt) (starknetrpc.TransactionReceipt, error) { if c.defaultTimeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.defaultTimeout) @@ -174,7 +175,7 @@ func (c *Client) TransactionReceipt(ctx context.Context, hash caigotypes.Felt) ( } -func (c *Client) Events(ctx context.Context, input caigorpc.EventsInput) (*caigorpc.EventsOutput, error) { +func (c *Client) Events(ctx context.Context, input starknetrpc.EventsInput) (*starknetrpc.EventChunk, error) { if c.defaultTimeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.defaultTimeout) @@ -191,14 +192,17 @@ func (c *Client) Events(ctx context.Context, input caigorpc.EventsInput) (*caigo return out, nil } -func (c *Client) AccountNonce(ctx context.Context, accountAddress caigotypes.Felt) (*big.Int, error) { +func (c *Client) AccountNonce(ctx context.Context, accountAddress *felt.Felt) (*big.Int, error) { if c.defaultTimeout != 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, c.defaultTimeout) defer cancel() } - sender := caigotypes.BigToFelt(big.NewInt((0))) // not actually used in account.Nonce() + sender, err := starknetutils.BigIntToFelt(big.NewInt((0))) // not actually used in account.Nonce() + if err != nil { + return nil, errors.Wrap(err, "error in client.AccountNonce") + } account, err := caigo.NewRPCAccount(sender, accountAddress, nil, c.Provider, caigo.AccountVersion1) if err != nil { return nil, errors.Wrap(err, "error in client.AccountNonce") diff --git a/relayer/pkg/starknet/client_test.go b/relayer/pkg/starknet/client_test.go index d79e6a62c..dd7f422c8 100644 --- a/relayer/pkg/starknet/client_test.go +++ b/relayer/pkg/starknet/client_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo/gateway" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/starknet.go/gateway" + starknettypes "github.com/NethermindEth/starknet.go/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -40,12 +40,12 @@ func TestRPCClient(t *testing.T) { switch call.Method { case "starknet_chainId": - id := caigotypes.BigToHex(caigotypes.UTF8StrToBig(chainID)) + id := starknettypes.BigToHex(starknettypes.UTF8StrToBig(chainID)) out = []byte(fmt.Sprintf(`{"result": "%s"}`, id)) case "starknet_blockNumber": out = []byte(`{"result": 1}`) default: - require.False(t, true, "unsupported RPC method") + require.False(t, true, "unsupported RPC method %s", call.Method) } _, err := w.Write(out) require.NoError(t, err) diff --git a/relayer/pkg/starknet/mocks/Reader.go b/relayer/pkg/starknet/mocks/Reader.go index 5d0bcfeb1..f5229e04a 100644 --- a/relayer/pkg/starknet/mocks/Reader.go +++ b/relayer/pkg/starknet/mocks/Reader.go @@ -6,13 +6,13 @@ import ( context "context" big "math/big" + felt "github.com/NethermindEth/juno/core/felt" + mock "github.com/stretchr/testify/mock" - rpcv02 "github.com/smartcontractkit/caigo/rpcv02" + rpc "github.com/NethermindEth/starknet.go/rpc" starknet "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet" - - types "github.com/smartcontractkit/caigo/types" ) // Reader is an autogenerated mock type for the Reader type @@ -21,15 +21,15 @@ type Reader struct { } // AccountNonce provides a mock function with given fields: _a0, _a1 -func (_m *Reader) AccountNonce(_a0 context.Context, _a1 types.Felt) (*big.Int, error) { +func (_m *Reader) AccountNonce(_a0 context.Context, _a1 *felt.Felt) (*big.Int, error) { ret := _m.Called(_a0, _a1) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (*big.Int, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (*big.Int, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) *big.Int); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) *big.Int); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { @@ -37,7 +37,7 @@ func (_m *Reader) AccountNonce(_a0 context.Context, _a1 types.Felt) (*big.Int, e } } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -47,23 +47,23 @@ func (_m *Reader) AccountNonce(_a0 context.Context, _a1 types.Felt) (*big.Int, e } // BlockWithTxHashes provides a mock function with given fields: ctx, blockID -func (_m *Reader) BlockWithTxHashes(ctx context.Context, blockID rpcv02.BlockID) (*rpcv02.Block, error) { +func (_m *Reader) BlockWithTxHashes(ctx context.Context, blockID rpc.BlockID) (*rpc.Block, error) { ret := _m.Called(ctx, blockID) - var r0 *rpcv02.Block + var r0 *rpc.Block var r1 error - if rf, ok := ret.Get(0).(func(context.Context, rpcv02.BlockID) (*rpcv02.Block, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, rpc.BlockID) (*rpc.Block, error)); ok { return rf(ctx, blockID) } - if rf, ok := ret.Get(0).(func(context.Context, rpcv02.BlockID) *rpcv02.Block); ok { + if rf, ok := ret.Get(0).(func(context.Context, rpc.BlockID) *rpc.Block); ok { r0 = rf(ctx, blockID) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*rpcv02.Block) + r0 = ret.Get(0).(*rpc.Block) } } - if rf, ok := ret.Get(1).(func(context.Context, rpcv02.BlockID) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, rpc.BlockID) error); ok { r1 = rf(ctx, blockID) } else { r1 = ret.Error(1) @@ -73,23 +73,23 @@ func (_m *Reader) BlockWithTxHashes(ctx context.Context, blockID rpcv02.BlockID) } // Call provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Reader) Call(_a0 context.Context, _a1 types.FunctionCall, _a2 rpcv02.BlockID) ([]string, error) { +func (_m *Reader) Call(_a0 context.Context, _a1 rpc.FunctionCall, _a2 rpc.BlockID) ([]*felt.Felt, error) { ret := _m.Called(_a0, _a1, _a2) - var r0 []string + var r0 []*felt.Felt var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.FunctionCall, rpcv02.BlockID) ([]string, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, rpc.FunctionCall, rpc.BlockID) ([]*felt.Felt, error)); ok { return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, types.FunctionCall, rpcv02.BlockID) []string); ok { + if rf, ok := ret.Get(0).(func(context.Context, rpc.FunctionCall, rpc.BlockID) []*felt.Felt); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + r0 = ret.Get(0).([]*felt.Felt) } } - if rf, ok := ret.Get(1).(func(context.Context, types.FunctionCall, rpcv02.BlockID) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, rpc.FunctionCall, rpc.BlockID) error); ok { r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) @@ -99,19 +99,19 @@ func (_m *Reader) Call(_a0 context.Context, _a1 types.FunctionCall, _a2 rpcv02.B } // CallContract provides a mock function with given fields: _a0, _a1 -func (_m *Reader) CallContract(_a0 context.Context, _a1 starknet.CallOps) ([]string, error) { +func (_m *Reader) CallContract(_a0 context.Context, _a1 starknet.CallOps) ([]*felt.Felt, error) { ret := _m.Called(_a0, _a1) - var r0 []string + var r0 []*felt.Felt var r1 error - if rf, ok := ret.Get(0).(func(context.Context, starknet.CallOps) ([]string, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, starknet.CallOps) ([]*felt.Felt, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, starknet.CallOps) []string); ok { + if rf, ok := ret.Get(0).(func(context.Context, starknet.CallOps) []*felt.Felt); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + r0 = ret.Get(0).([]*felt.Felt) } } @@ -125,23 +125,23 @@ func (_m *Reader) CallContract(_a0 context.Context, _a1 starknet.CallOps) ([]str } // Events provides a mock function with given fields: ctx, input -func (_m *Reader) Events(ctx context.Context, input rpcv02.EventsInput) (*rpcv02.EventsOutput, error) { +func (_m *Reader) Events(ctx context.Context, input rpc.EventsInput) (*rpc.EventChunk, error) { ret := _m.Called(ctx, input) - var r0 *rpcv02.EventsOutput + var r0 *rpc.EventChunk var r1 error - if rf, ok := ret.Get(0).(func(context.Context, rpcv02.EventsInput) (*rpcv02.EventsOutput, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, rpc.EventsInput) (*rpc.EventChunk, error)); ok { return rf(ctx, input) } - if rf, ok := ret.Get(0).(func(context.Context, rpcv02.EventsInput) *rpcv02.EventsOutput); ok { + if rf, ok := ret.Get(0).(func(context.Context, rpc.EventsInput) *rpc.EventChunk); ok { r0 = rf(ctx, input) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*rpcv02.EventsOutput) + r0 = ret.Get(0).(*rpc.EventChunk) } } - if rf, ok := ret.Get(1).(func(context.Context, rpcv02.EventsInput) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, rpc.EventsInput) error); ok { r1 = rf(ctx, input) } else { r1 = ret.Error(1) @@ -175,23 +175,23 @@ func (_m *Reader) LatestBlockHeight(_a0 context.Context) (uint64, error) { } // TransactionByHash provides a mock function with given fields: _a0, _a1 -func (_m *Reader) TransactionByHash(_a0 context.Context, _a1 types.Felt) (rpcv02.Transaction, error) { +func (_m *Reader) TransactionByHash(_a0 context.Context, _a1 *felt.Felt) (rpc.Transaction, error) { ret := _m.Called(_a0, _a1) - var r0 rpcv02.Transaction + var r0 rpc.Transaction var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (rpcv02.Transaction, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (rpc.Transaction, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) rpcv02.Transaction); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) rpc.Transaction); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(rpcv02.Transaction) + r0 = ret.Get(0).(rpc.Transaction) } } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -201,23 +201,23 @@ func (_m *Reader) TransactionByHash(_a0 context.Context, _a1 types.Felt) (rpcv02 } // TransactionReceipt provides a mock function with given fields: _a0, _a1 -func (_m *Reader) TransactionReceipt(_a0 context.Context, _a1 types.Felt) (rpcv02.TransactionReceipt, error) { +func (_m *Reader) TransactionReceipt(_a0 context.Context, _a1 *felt.Felt) (rpc.TransactionReceipt, error) { ret := _m.Called(_a0, _a1) - var r0 rpcv02.TransactionReceipt + var r0 rpc.TransactionReceipt var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) (rpcv02.TransactionReceipt, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) (rpc.TransactionReceipt, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, types.Felt) rpcv02.TransactionReceipt); ok { + if rf, ok := ret.Get(0).(func(context.Context, *felt.Felt) rpc.TransactionReceipt); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(rpcv02.TransactionReceipt) + r0 = ret.Get(0).(rpc.TransactionReceipt) } } - if rf, ok := ret.Get(1).(func(context.Context, types.Felt) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *felt.Felt) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) diff --git a/relayer/pkg/starknet/types.go b/relayer/pkg/starknet/types.go index 8c949c307..d79603af6 100644 --- a/relayer/pkg/starknet/types.go +++ b/relayer/pkg/starknet/types.go @@ -1,11 +1,11 @@ package starknet import ( - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" ) type CallOps struct { - ContractAddress caigotypes.Felt - Selector string - Calldata []string + ContractAddress *felt.Felt + Selector *felt.Felt + Calldata []*felt.Felt } diff --git a/relayer/pkg/starknet/utils.go b/relayer/pkg/starknet/utils.go index 8cc1c2ecc..0a45ad6b3 100644 --- a/relayer/pkg/starknet/utils.go +++ b/relayer/pkg/starknet/utils.go @@ -5,7 +5,7 @@ import ( "fmt" "math/big" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "github.com/pkg/errors" "golang.org/x/exp/constraints" @@ -88,41 +88,14 @@ func DecodeFelts(felts []*big.Int) ([]byte, error) { return data, nil } -func FeltToUnsignedBig(felt caigotypes.Felt) (num *big.Int, err error) { - num = felt.Big() - if caigotypes.MaxFelt.Big().Cmp(num) == -1 { - return nil, fmt.Errorf("felt value is too large: %s", num) - } - // will always return a non-negative value because it uses Bytes() behind the scenes - return num, nil -} - -func HexToUnsignedBig(str string) (num *big.Int, err error) { - felt := caigotypes.StrToFelt(str) - return FeltToUnsignedBig(felt) -} - -func FeltsToBig(in []caigotypes.Felt) (out []*big.Int) { +func FeltsToBig(in []*felt.Felt) (out []*big.Int) { for _, f := range in { - out = append(out, f.Big()) + out = append(out, f.BigInt(big.NewInt(0))) } return out } -// StringsToFelt maps felts from 'string' (hex) representation to 'caigo.Felt' representation -func StringsToFelt(in []string) (out []caigotypes.Felt, _ error) { - if in == nil { - return nil, errors.New("invalid: input value") - } - - for _, f := range in { - out = append(out, caigotypes.StrToFelt(f)) - } - - return out, nil -} - /* Testing utils - do not use (XXX) outside testing context */ func XXXMustHexDecodeString(data string) []byte { diff --git a/relayer/pkg/starknet/utils_test.go b/relayer/pkg/starknet/utils_test.go index 15d11ff8f..69ff2ce86 100644 --- a/relayer/pkg/starknet/utils_test.go +++ b/relayer/pkg/starknet/utils_test.go @@ -7,8 +7,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - caigotypes "github.com/smartcontractkit/caigo/types" ) var ( @@ -40,28 +38,6 @@ func TestPadBytes(t *testing.T) { } } -func TestFeltToUnsignedBig(t *testing.T) { - - negativeBig := caigotypes.BigToFelt(big.NewInt(-100)) - // negative felts are not supported - num, err := FeltToUnsignedBig(negativeBig) - assert.NoError(t, err) - assert.Equal(t, num, big.NewInt(100)) - - positiveBig := caigotypes.BigToFelt(big.NewInt(100)) - num, err = FeltToUnsignedBig(positiveBig) - assert.NoError(t, err) - assert.Equal(t, num, big.NewInt(100)) - -} - -func TestHexToUnSignedBig(t *testing.T) { - // Positive value (99) - answer, err := HexToUnsignedBig("0x63") - assert.NoError(t, err) - assert.Equal(t, big.NewInt(99), answer) -} - func TestDecodeFeltFails(t *testing.T) { val, _ := new(big.Int).SetString("1231927389172389172983712738127391273891", 10)