diff --git a/.github/workflows/contracts.yml b/.github/workflows/contracts.yml index 3800499bf..3cc470e0f 100644 --- a/.github/workflows/contracts.yml +++ b/.github/workflows/contracts.yml @@ -23,9 +23,6 @@ jobs: - name: Install Cairo uses: ./.github/actions/install-cairo - - name: Install starknet-devnet (via venv+pip) - run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt - - name: Test run: nix develop -c make test-ts-contracts diff --git a/.github/workflows/integration_contracts.yml b/.github/workflows/integration_contracts.yml index 835082dd8..fa421a134 100644 --- a/.github/workflows/integration_contracts.yml +++ b/.github/workflows/integration_contracts.yml @@ -23,8 +23,5 @@ jobs: - name: Install Cairo uses: ./.github/actions/install-cairo - - name: Install starknet-devnet (via venv+pip) - run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt - - name: Test run: nix develop -c make test-integration-contracts diff --git a/.github/workflows/integration_gauntlet.yml b/.github/workflows/integration_gauntlet.yml index 5dc4bfe40..892c42002 100644 --- a/.github/workflows/integration_gauntlet.yml +++ b/.github/workflows/integration_gauntlet.yml @@ -49,9 +49,6 @@ jobs: - name: Install Cairo uses: ./.github/actions/install-cairo - - name: Install starknet-devnet (via venv+pip) - run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt - - name: Test run: nix develop -c make test-integration-gauntlet diff --git a/.github/workflows/relayer.yml b/.github/workflows/relayer.yml index 3227a9110..2bbbe0a63 100644 --- a/.github/workflows/relayer.yml +++ b/.github/workflows/relayer.yml @@ -35,8 +35,5 @@ jobs: ./relayer/coverage.txt ./relayer/race_coverage.txt - - name: Install starknet-devnet (via venv+pip) - run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt - - name: Integration Test run: nix develop -c make test-integration-go diff --git a/contracts/constraints.txt b/contracts/constraints.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/contracts/requirements.txt b/contracts/requirements.txt deleted file mode 100644 index a50aff25e..000000000 --- a/contracts/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -ecdsa -fastecdsa -sympy -cairo-lang>=0.12.1 -starknet-devnet>=0.6.0 diff --git a/flake.lock b/flake.lock index 99fbfe931..d21fabcde 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "owner": "numtide", "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "type": "github" }, "original": { @@ -38,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1697456312, - "narHash": "sha256-roiSnrqb5r+ehnKCauPLugoU8S36KgmWraHgRqVYndo=", + "lastModified": 1704538339, + "narHash": "sha256-1734d3mQuux9ySvwf6axRWZRBhtcZA9Q8eftD6EZg6U=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ca012a02bf8327be9e488546faecae5e05d7d749", + "rev": "46ae0210ce163b3cba6c7da08840c1d63de9c701", "type": "github" }, "original": { @@ -81,11 +81,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1692238117, - "narHash": "sha256-gOoxig/GBuGOYWqE3+7OMrgPVduxjjsbo4qikRb1h3s=", + "lastModified": 1704680242, + "narHash": "sha256-5bD6iSPDgVTLly2gy2oJVwzuyuFZOz2p4qt8c8UoYIE=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "3e0e4ec062706ebba759795ad18ad72ad69d41f3", + "rev": "2037779e018ebc2d381001a891e2a793fce7a74f", "type": "github" }, "original": { diff --git a/integration-tests/common/common.go b/integration-tests/common/common.go index 64d4248d8..477574ece 100644 --- a/integration-tests/common/common.go +++ b/integration-tests/common/common.go @@ -13,8 +13,6 @@ import ( "github.com/rs/zerolog/log" "gopkg.in/guregu/null.v4" - "github.com/smartcontractkit/caigo/gateway" - "github.com/smartcontractkit/chainlink-starknet/ops/devnet" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/alias" @@ -30,7 +28,7 @@ var ( serviceKeyL2 = "starknet-dev" serviceKeyChainlink = "chainlink" chainName = "starknet" - chainId = gateway.GOERLI_ID + chainId = "SN_GOERLI" ) type Common struct { diff --git a/integration-tests/common/test_common.go b/integration-tests/common/test_common.go index d3ec5d8c2..59534111d 100644 --- a/integration-tests/common/test_common.go +++ b/integration-tests/common/test_common.go @@ -10,8 +10,9 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" + curve "github.com/NethermindEth/starknet.go/curve" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -51,7 +52,7 @@ func init() { } func pubKeyToDevnetAccount(pubkey starkkey.PublicKey) ([]byte, error) { - xHash, err := caigo.Curve.ComputeHashOnElements([]*big.Int{pubkey.X}) + xHash, err := curve.Curve.ComputeHashOnElements([]*big.Int{pubkey.X}) if err != nil { return nil, err } @@ -62,7 +63,7 @@ func pubKeyToDevnetAccount(pubkey starkkey.PublicKey) ([]byte, error) { ops.DevnetClassHash, xHash, } - hash, err := caigo.Curve.ComputeHashOnElements(elements) + hash, err := curve.Curve.ComputeHashOnElements(elements) if err != nil { return nil, err } @@ -266,20 +267,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: starknetutils.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: starknetutils.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 +298,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 +370,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: starknetutils.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 f7b100400..79136df08 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -3,10 +3,11 @@ module github.com/smartcontractkit/chainlink-starknet/integration-tests go 1.21.4 require ( + github.com/NethermindEth/juno v0.3.1 + github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1 github.com/google/uuid v1.4.0 github.com/lib/pq v1.10.9 github.com/rs/zerolog v1.30.0 - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218150613-43bf581ae327 github.com/smartcontractkit/chainlink-starknet/ops v0.0.0-20231117204155-b253a2f56664 github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231215215547-68a402815b84 @@ -18,6 +19,12 @@ require ( gopkg.in/guregu/null.v4 v4.0.0 ) +require ( + github.com/bits-and-blooms/bitset v1.7.0 // indirect + github.com/consensys/gnark-crypto v0.11.0 // indirect + github.com/test-go/testify v1.1.4 // indirect +) + require ( contrib.go.opencensus.io/exporter/stackdriver v0.13.5 // indirect cosmossdk.io/api v0.3.1 // indirect @@ -79,6 +86,7 @@ require ( github.com/cometbft/cometbft v0.37.2 // indirect github.com/cometbft/cometbft-db v0.8.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect github.com/containerd/containerd v1.7.7 // indirect github.com/containerd/continuity v0.4.3 // indirect github.com/containerd/log v0.1.0 // indirect @@ -262,6 +270,7 @@ require ( github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/moby/patternmatcher v0.6.0 // indirect github.com/moby/spdystream v0.2.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect @@ -320,6 +329,7 @@ require ( github.com/shopspring/decimal v1.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/slack-go/slack v0.12.2 // indirect + github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect github.com/smartcontractkit/chainlink-automation v1.0.1 // indirect github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231215215216-51cb121f7f33 // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 // indirect @@ -428,6 +438,7 @@ require ( k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect nhooyr.io/websocket v1.8.7 // indirect pgregory.net/rapid v0.5.5 // indirect + rsc.io/tmplfunc v0.0.3 // indirect sigs.k8s.io/controller-runtime v0.13.0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.12.1 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 60b3e67a8..332500cb5 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -127,6 +127,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.11.1 h1:hJ3s7GbWlGK4YVV92sO88BQSyF4ZLVy7/awqOlPxFbA= github.com/Microsoft/hcsshim v0.11.1/go.mod h1:nFJmaO4Zr5Y7eADdFOpYswDDlNVbvcIJJNJLECr5JQg= +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.6.1-0.20231218140327-915109ab5bc1 h1:9SBvy3eZut1X+wEyAFqfb7ADGj8IQw7ZnlkMwz0YOTY= +github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1/go.mod h1:V6qrbi1+fTDCftETIT1grBXIf+TvWP/4Aois1a9EF1E= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -193,6 +197,8 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ 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= @@ -277,6 +283,10 @@ github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AK github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0= 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/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +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/containerd v1.7.7 h1:QOC2K4A42RQpcrZyptP6z9EJZnlHfHJUfZrAAHe15q4= github.com/containerd/containerd v1.7.7/go.mod h1:3c4XZv6VeT9qgf9GMTxNTMFxGJrGpI2vz1yk4ye+YY8= github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8= @@ -715,6 +725,7 @@ github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -1099,6 +1110,9 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= @@ -2185,6 +2199,8 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sigs.k8s.io/controller-runtime v0.13.0 h1:iqa5RNciy7ADWnIc8QxCbOX5FEKVR3uxVxKHRMc2WIQ= sigs.k8s.io/controller-runtime v0.13.0/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/monitoring/go.mod b/monitoring/go.mod index d0d07b813..6baec3c2e 100644 --- a/monitoring/go.mod +++ b/monitoring/go.mod @@ -5,8 +5,9 @@ go 1.21 toolchain go1.21.1 require ( + github.com/NethermindEth/juno v0.3.1 + github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1 github.com/prometheus/client_golang v1.17.0 - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218150613-43bf581ae327 github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20230508053614-9f2fd5fd4ff1 github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 @@ -17,11 +18,14 @@ require ( require ( cloud.google.com/go/compute/metadata v0.2.3 // 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/btcsuite/btcd/chaincfg/chainhash v1.0.3 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/confluentinc/confluent-kafka-go/v2 v2.3.0 // indirect + github.com/consensys/bavard v0.1.13 // 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 @@ -36,7 +40,6 @@ require ( github.com/go-stack/stack v1.8.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect - github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.3.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0 // indirect @@ -52,6 +55,7 @@ require ( github.com/mattn/go-isatty v0.0.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 // indirect github.com/oklog/run v1.0.0 // indirect @@ -64,6 +68,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.2.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 @@ -89,6 +94,7 @@ require ( google.golang.org/protobuf v1.31.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) replace ( diff --git a/monitoring/go.sum b/monitoring/go.sum index 2faaa3853..6225ec13d 100644 --- a/monitoring/go.sum +++ b/monitoring/go.sum @@ -46,10 +46,16 @@ github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VM github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/hcsshim v0.9.4 h1:mnUj0ivWy6UzbB1uLFqKR6F+ZyiDc7j4iGgHTpO+5+I= github.com/Microsoft/hcsshim v0.9.4/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc= +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.6.1-0.20231218140327-915109ab5bc1 h1:9SBvy3eZut1X+wEyAFqfb7ADGj8IQw7ZnlkMwz0YOTY= +github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1/go.mod h1:V6qrbi1+fTDCftETIT1grBXIf+TvWP/4Aois1a9EF1E= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= 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.3 h1:SDlJ7bAm4ewvrmZtR0DaiYbQGdKPeaaIm7bM+qRhFeU= @@ -75,12 +81,16 @@ github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5b github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk= 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/confluentinc/confluent-kafka-go/v2 v2.3.0 h1:icCHutJouWlQREayFwCc7lxDAhws08td+W3/gdqgZts= github.com/confluentinc/confluent-kafka-go/v2 v2.3.0/go.mod h1:/VTy8iEpe6mD9pkCH5BhijlUl8ulUXymKv1Qig5Rgb8= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +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/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA= github.com/containerd/cgroups v1.0.4/go.mod h1:nLNQtsF7Sl2HxNebu77i1R0oDlhiTG+kO4JTrUzo6IA= github.com/containerd/containerd v1.6.8 h1:h4dOFDwzHmqFEP754PgfgTeVXFnLiRc6kiqC7tplDJs= @@ -155,6 +165,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -185,12 +197,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= -github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -201,6 +210,7 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -249,6 +259,8 @@ 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/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a h1:dHCfT5W7gghzPtfsW488uPmEOm85wewI+ypUwibyTdU= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/linkedin/goavro/v2 v2.9.7/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA= github.com/linkedin/goavro/v2 v2.12.0 h1:rIQQSj8jdAUlKQh6DttK8wCRv4t4QO09g1C4aBWXslg= github.com/linkedin/goavro/v2 v2.12.0/go.mod h1:KXx+erlq+RPlGSPmLF7xGo6SAbh8sCQ53x064+ioxhk= @@ -270,6 +282,9 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs= github.com/moby/sys/mount v0.3.3/go.mod h1:PBaEorSNTLG5t/+4EgukEQVlAvVEc6ZjTySwKdqp5K0= github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78= @@ -320,8 +335,6 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -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-common v0.1.7-0.20231218150613-43bf581ae327 h1:7P+djpKBMQ2Cpv1ieUQdkZvDLt6owPvniHfMHSPFYjQ= github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218150613-43bf581ae327/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss= @@ -330,6 +343,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 h1:R9NkVN+1fooUJFsN9zj9gDY1B+zv54zNO785RQZRVfE= github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8/go.mod h1:2lyRkw/qLQgUWlrWWmq5nj0y90rWeO6Y+v+fCakRgb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -348,6 +363,8 @@ 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.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= +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/testcontainers/testcontainers-go v0.14.0 h1:h0D5GaYG9mhOWr2qHdEKDXpkce/VlvaYOCzTRi6UBi8= github.com/testcontainers/testcontainers-go v0.14.0/go.mod h1:hSRGJ1G8Q5Bw2gXgPulJOLlEBaYJHeBSOkQM5JLG+JQ= github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= @@ -701,3 +718,5 @@ honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/monitoring/pkg/monitoring/source_envelope.go b/monitoring/pkg/monitoring/source_envelope.go index 85c7322d3..323bdf788 100644 --- a/monitoring/pkg/monitoring/source_envelope.go +++ b/monitoring/pkg/monitoring/source_envelope.go @@ -6,7 +6,8 @@ import ( "math/big" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/smartcontractkit/libocr/offchainreporting2/types" "go.uber.org/multierr" @@ -37,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 } @@ -49,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 } @@ -116,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, @@ -142,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) @@ -156,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: starknetutils.GetSelectorFromNameFelt("balanceOf"), + Calldata: []*felt.Felt{contractAddress}, }) if err != nil { return nil, fmt.Errorf("failed call to ECR20 contract, balanceOf method: %w", err) @@ -168,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 6d60c5437..0833f37c5 100644 --- a/monitoring/pkg/monitoring/source_envelope_test.go +++ b/monitoring/pkg/monitoring/source_envelope_test.go @@ -6,8 +6,7 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -66,7 +65,7 @@ func TestEnvelopeSource(t *testing.T) { ContractAddress: chainConfig.GetLinkTokenAddress(), Selector: "balanceOf", Calldata: []string{ - caigo.HexToBN(feedConfig.ContractAddress).String(), + starknetutils.HexToBN(feedConfig.ContractAddress).String(), }, }, ).Return(starknetReaderCallContractBalanceOfResponse, nil) @@ -94,7 +93,7 @@ var ( { RoundId: 0xf5b, LatestAnswer: bigIntFromString("-900000000"), - Transmitter: caigotypes.StrToFelt("634447934223750826572902672583054702307815157196919304685470566142330202833"), + Transmitter: starknetutils.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 15d0bce6e..9b3d15657 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" + "github.com/NethermindEth/juno/core/felt" + starknetutils "github.com/NethermindEth/starknet.go/utils" relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" @@ -32,8 +33,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 } @@ -43,7 +48,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 352c30b60..19ca6a885 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" + "github.com/NethermindEth/juno/core/felt" + starknetutils "github.com/NethermindEth/starknet.go/utils" relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" @@ -28,8 +29,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{}, @@ -41,7 +46,7 @@ func (s *txResultsSourceFactory) GetType() string { } type txResultsSource struct { - contractAddress caigotypes.Hash + contractAddress *felt.Felt ocr2Reader ocr2.OCR2Reader prevRoundID uint32 diff --git a/ops/charts/devnet/templates/deployment.yaml b/ops/charts/devnet/templates/deployment.yaml index 3e920911d..df4bc41e7 100644 --- a/ops/charts/devnet/templates/deployment.yaml +++ b/ops/charts/devnet/templates/deployment.yaml @@ -31,7 +31,7 @@ spec: - "-c" - | mkdir -p cairo-build - curl -L --output release.tgz https://github.com/starkware-libs/cairo/releases/download/v2.0.2/release-x86_64-unknown-linux-musl.tar.gz + curl -L --output release.tgz https://github.com/starkware-libs/cairo/releases/download/v2.4.3/release-x86_64-unknown-linux-musl.tar.gz tar xzf release.tgz mv cairo/* cairo-build/ volumeMounts: @@ -47,8 +47,8 @@ spec: {{- else }} - name: cairo-build mountPath: /cairo-build - image: "{{ .Values.repository | default "shardlabs/starknet-devnet"}}:{{ .Values.tag | default "0.6.0"}}" - args: ["--sierra-compiler-path", "/cairo-build/bin/starknet-sierra-compile", "--lite-mode", "--port", {{ .Values.service.internalPort | quote}}, "--seed", {{ .Values.seed | quote}}] + image: "{{ .Values.repository | default "shardlabs/starknet-devnet-rs"}}:{{ .Values.tag | default "latest"}}" + args: ["--port", {{ .Values.service.internalPort | quote}}, "--seed", {{ .Values.seed | quote}}, "--account-class", "cairo1"] {{- end }} imagePullPolicy: IfNotPresent {{- if eq .Values.real_node true }} 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/devnet/environment.go b/ops/devnet/environment.go index 082754a49..24389ac5d 100644 --- a/ops/devnet/environment.go +++ b/ops/devnet/environment.go @@ -72,8 +72,8 @@ func defaultProps() map[string]any { "replicas": "1", "starknet-dev": map[string]any{ "image": map[string]any{ - "image": "shardlabs/starknet-devnet", - "version": "v0.6.0", + "image": "shardlabs/starknet-devnet-rs", + "version": "5d2536a99852b1a61bbbfdcaa6755cb4275bffddm", }, "resources": map[string]any{ "requests": map[string]any{ diff --git a/ops/go.mod b/ops/go.mod index aec90363e..68ef86922 100644 --- a/ops/go.mod +++ b/ops/go.mod @@ -5,9 +5,9 @@ go 1.21 toolchain go1.21.1 require ( + github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1 github.com/go-resty/resty/v2 v2.7.0 github.com/rs/zerolog v1.30.0 - 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.19.1 @@ -20,11 +20,13 @@ require ( github.com/MakeNowJust/heredoc v1.0.0 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/NethermindEth/juno v0.3.1 // indirect github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/avast/retry-go v3.0.0+incompatible // indirect github.com/aws/constructs-go/constructs/v10 v10.1.255 // indirect github.com/aws/jsii-runtime-go v1.75.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.3.2 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3 // indirect github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.7.5 // indirect @@ -32,6 +34,8 @@ require ( 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/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.11.0 // indirect github.com/containerd/containerd v1.7.3 // indirect github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -66,7 +70,6 @@ require ( github.com/google/btree v1.1.2 // indirect github.com/google/gnostic v0.6.9 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.1 // indirect @@ -93,6 +96,7 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/moby/patternmatcher v0.5.0 // indirect github.com/moby/spdystream v0.2.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect @@ -125,6 +129,7 @@ require ( github.com/spf13/cobra v1.6.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.8.4 // indirect + github.com/test-go/testify v1.1.4 // indirect github.com/testcontainers/testcontainers-go v0.23.0 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect @@ -175,6 +180,7 @@ require ( k8s.io/kube-openapi v0.0.0-20230525220651-2546d827e515 // indirect k8s.io/kubectl v0.25.11 // indirect k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect + rsc.io/tmplfunc v0.0.3 // indirect sigs.k8s.io/controller-runtime v0.13.0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.12.1 // indirect diff --git a/ops/go.sum b/ops/go.sum index 5bd5e7d49..c7d907519 100644 --- a/ops/go.sum +++ b/ops/go.sum @@ -54,6 +54,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.10.0-rc.8 h1:YSZVvlIIDD1UxQpJp0h+dnpLUw+TrY0cx8obKsp3bek= github.com/Microsoft/hcsshim v0.10.0-rc.8/go.mod h1:OEthFdQv/AD2RAdzR6Mm1N1KPCztGKDurW1Z8b8VGMM= +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.6.1-0.20231218140327-915109ab5bc1 h1:9SBvy3eZut1X+wEyAFqfb7ADGj8IQw7ZnlkMwz0YOTY= +github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1/go.mod h1:V6qrbi1+fTDCftETIT1grBXIf+TvWP/4Aois1a9EF1E= 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= @@ -70,6 +74,8 @@ github.com/aws/jsii-runtime-go v1.75.0 h1:NhpUfyiL7/wsRuUekFsz8FFBCYLfPD/l61kKg9 github.com/aws/jsii-runtime-go v1.75.0/go.mod h1:TKCyrtM0pygEPo4rDZzbMSDNCDNTSYSN6/mGyHI6O3I= 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.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3 h1:SDlJ7bAm4ewvrmZtR0DaiYbQGdKPeaaIm7bM+qRhFeU= @@ -106,10 +112,14 @@ github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5b github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk= 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/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +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/containerd v1.7.3 h1:cKwYKkP1eTj54bP3wCdXXBymmKRQMrWjkLSWZZJDa8o= github.com/containerd/containerd v1.7.3/go.mod h1:32FOM4/O0RkNg7AjQj3hDzN9cUGtu+HMvaKUNiqCZB8= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -226,6 +236,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -260,13 +272,10 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= -github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -284,6 +293,7 @@ github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYa github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -349,6 +359,8 @@ 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/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a h1:dHCfT5W7gghzPtfsW488uPmEOm85wewI+ypUwibyTdU= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= 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/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= @@ -374,6 +386,9 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= @@ -454,8 +469,6 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -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-common v0.1.7-0.20231218150613-43bf581ae327 h1:7P+djpKBMQ2Cpv1ieUQdkZvDLt6owPvniHfMHSPFYjQ= github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218150613-43bf581ae327/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs= github.com/smartcontractkit/chainlink-env v0.3.29 h1:hcIw/BeuB0wKiiE3umAUNBZzWkHO24XF3OW9xSrlMbI= @@ -493,6 +506,8 @@ 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.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs= github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/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/testcontainers/testcontainers-go v0.23.0 h1:ERYTSikX01QczBLPZpqsETTBO7lInqEP349phDOVJVs= github.com/testcontainers/testcontainers-go v0.23.0/go.mod h1:3gzuZfb7T9qfcH2pHpV4RLlWrPjeWNQah6XlYQ32c4I= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= @@ -914,6 +929,8 @@ k8s.io/utils v0.0.0-20230711102312-30195339c3c7/go.mod h1:OLgZIPagt7ERELqWJFomSt rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sigs.k8s.io/controller-runtime v0.13.0 h1:iqa5RNciy7ADWnIc8QxCbOX5FEKVR3uxVxKHRMc2WIQ= sigs.k8s.io/controller-runtime v0.13.0/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/ops/scripts/devnet-hardhat-down.sh b/ops/scripts/devnet-hardhat-down.sh index 193628820..4b9b02111 100755 --- a/ops/scripts/devnet-hardhat-down.sh +++ b/ops/scripts/devnet-hardhat-down.sh @@ -1,25 +1,25 @@ #!/usr/bin/env bash # TODO: this script needs to be replaced with a predefined K8s enviroment -echo "Cleaning up Starknet Devnet container..." +echo "Cleaning up Hardhat container..." -dpid=`docker ps | grep chainlink-starknet.starknet-devnet | awk '{print $1}'`; -echo "Checking for existing 'chainlink-starknet.starknet-devnet' docker container..." +dpid=`docker ps | grep chainlink-starknet.hardhat | awk '{print $1}'`; +echo "Checking for existing 'chainlink-starknet.hardhat' docker container..." if [ -z "$dpid" ] then - echo "No docker Starknet Devnet container running."; + echo "No docker Hardhat container running."; else docker kill $dpid; docker rm $dpid; fi -echo "Cleaning up Hardhat container..." +echo "Cleaning up Starknet Devnet container..." -dpid=`docker ps | grep chainlink-starknet.hardhat | awk '{print $1}'`; -echo "Checking for existing 'chainlink-starknet.hardhat' docker container..." +dpid=`docker ps | grep chainlink-starknet.starknet-devnet | awk '{print $1}'`; +echo "Checking for existing 'chainlink-starknet.starknet-devnet' docker container..." if [ -z "$dpid" ] then - echo "No docker Hardhat container running."; + echo "No docker Starknet Devnet container running."; else docker kill $dpid; docker rm $dpid; diff --git a/ops/scripts/devnet-hardhat.sh b/ops/scripts/devnet-hardhat.sh index 39ae970ba..af0cca3b4 100755 --- a/ops/scripts/devnet-hardhat.sh +++ b/ops/scripts/devnet-hardhat.sh @@ -3,26 +3,9 @@ set -euo pipefail -cpu_struct=`arch`; -echo $cpu_struct; - -git_root="$(git rev-parse --show-toplevel)" -cairo_build_path="${git_root}/cairo-build" -cairo_sierra_compile_path="${cairo_build_path}/bin/starknet-sierra-compile" - -cairo_checkout_path="${git_root}/vendor/cairo" -cairo_compiler_manifest="${cairo_checkout_path}/Cargo.toml" - -if [ -f "${cairo_sierra_compile_path}" ]; then - docker_volume="${cairo_build_path}:/cairo-build" - startup_args="starknet-devnet --lite-mode --host 0.0.0.0 --sierra-compiler-path /cairo-build/bin/starknet-sierra-compile" -elif [ -f "${cairo_compiler_manifest}" ]; then - docker_volume="${cairo_checkout_path}:/cairo" - startup_args="(wget https://sh.rustup.rs -O - | sh -s -- -y) && apk add gmp-dev g++ gcc libffi-dev && PATH=\"/root/.cargo/bin:\${PATH}\" starknet-devnet --lite-mode --host 0.0.0.0 --cairo-compiler-manifest /cairo/Cargo.toml" -else - echo "No Cargo.toml; did you checkout the cairo git submodule?" - exit 1 -fi +# cpu_struct=`arch`; +# echo $cpu_struct; +cpu_struct="linux"; # Clean up first bash "$(dirname -- "$0";)/devnet-hardhat-down.sh" @@ -31,24 +14,24 @@ echo "Checking CPU structure..." if [[ $cpu_struct == *"arm"* ]] then echo "Starting arm devnet container..." - container_version="0.6.0-arm" + container_version="5d2536a99852b1a61bbbfdcaa6755cb4275bffdd-arm" else echo "Starting i386 devnet container..." - container_version="0.6.0" + container_version="5d2536a99852b1a61bbbfdcaa6755cb4275bffdd" fi -echo "Starting starknet-devnet: ${startup_args}" +echo "Starting starknet-devnet" # we need to replace the entrypoint because starknet-devnet's docker builds at 0.5.1 don't include cargo or gcc. docker run \ -p 127.0.0.1:5050:5050 \ -p 127.0.0.1:8545:8545 \ -d \ + -e RUST_LOG=debug \ --name chainlink-starknet.starknet-devnet \ - --volume "${docker_volume}" \ - --entrypoint sh \ - "shardlabs/starknet-devnet:${container_version}" \ - -c "${startup_args}" + "shardlabs/starknet-devnet-rs:${container_version}" \ + --seed 0 \ + --account-class cairo1 echo "Starting hardhat..." docker run --net container:chainlink-starknet.starknet-devnet -d --name chainlink-starknet.hardhat ethereumoptimism/hardhat-node:nightly @@ -65,7 +48,7 @@ do prev_output="${output}" fi - if [[ $output == *"Listening"* ]]; then + if [[ $output == *"listening"* ]]; then echo "" echo "starknet-devnet is ready." exit 0 diff --git a/relayer/go.mod b/relayer/go.mod index 6c90b15a2..20c429503 100644 --- a/relayer/go.mod +++ b/relayer/go.mod @@ -5,11 +5,12 @@ go 1.21 toolchain go1.21.1 require ( + github.com/NethermindEth/juno v0.3.1 + github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1 github.com/ethereum/go-ethereum v1.11.5 github.com/hashicorp/go-plugin v1.5.2 github.com/pelletier/go-toml/v2 v2.1.0 github.com/pkg/errors v0.9.1 - github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218150613-43bf581ae327 github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 github.com/stretchr/testify v1.8.4 @@ -21,10 +22,13 @@ require ( require ( cloud.google.com/go/compute/metadata v0.2.3 // 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/btcsuite/btcd/chaincfg/chainhash v1.0.3 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/consensys/bavard v0.1.13 // 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 @@ -38,7 +42,6 @@ require ( github.com/go-stack/stack v1.8.1 // indirect github.com/gogo/protobuf v1.3.3 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.3.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0 // indirect @@ -52,6 +55,7 @@ require ( github.com/mattn/go-isatty v0.0.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 // indirect github.com/oklog/run v1.0.0 // indirect @@ -62,6 +66,7 @@ require ( github.com/prometheus/procfs v0.11.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 @@ -84,6 +89,7 @@ require ( google.golang.org/protobuf v1.31.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) replace ( diff --git a/relayer/go.sum b/relayer/go.sum index 4203f417b..088f38132 100644 --- a/relayer/go.sum +++ b/relayer/go.sum @@ -40,10 +40,18 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 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/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +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.6.0 h1:nEEgn9wmLS3jj8W31RAnfyzHkZtS3nSypkqo/f4bhOM= +github.com/NethermindEth/starknet.go v0.6.0/go.mod h1:V6qrbi1+fTDCftETIT1grBXIf+TvWP/4Aois1a9EF1E= +github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1 h1:9SBvy3eZut1X+wEyAFqfb7ADGj8IQw7ZnlkMwz0YOTY= +github.com/NethermindEth/starknet.go v0.6.1-0.20231218140327-915109ab5bc1/go.mod h1:V6qrbi1+fTDCftETIT1grBXIf+TvWP/4Aois1a9EF1E= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= 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.3 h1:SDlJ7bAm4ewvrmZtR0DaiYbQGdKPeaaIm7bM+qRhFeU= @@ -69,10 +77,14 @@ github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5b github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk= 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/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +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= @@ -162,12 +174,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= -github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -178,6 +187,7 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -227,6 +237,8 @@ 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/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a h1:dHCfT5W7gghzPtfsW488uPmEOm85wewI+ypUwibyTdU= +github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -243,6 +255,9 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 h1:NHrXEjTNQY7P0Zfx1aMrNhpgxHmow66XQtm0aQLY0AE= @@ -274,8 +289,6 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= 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-common v0.1.7-0.20231218150613-43bf581ae327 h1:7P+djpKBMQ2Cpv1ieUQdkZvDLt6owPvniHfMHSPFYjQ= github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218150613-43bf581ae327/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss= @@ -284,6 +297,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 h1:R9NkVN+1fooUJFsN9zj9gDY1B+zv54zNO785RQZRVfE= github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8/go.mod h1:2lyRkw/qLQgUWlrWWmq5nj0y90rWeO6Y+v+fCakRgb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -300,6 +315,8 @@ 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.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= +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= @@ -652,3 +669,5 @@ honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/relayer/pkg/chainlink/ocr2/client.go b/relayer/pkg/chainlink/ocr2/client.go index 6a385c3cf..abcc6c112 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" + starknetutils "github.com/NethermindEth/starknet.go/utils" "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: starknetutils.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: starknetutils.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: starknetutils.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: starknetutils.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: starknetutils.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 := starknetutils.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 9ee04384d..436fd8bc3 100644 --- a/relayer/pkg/chainlink/ocr2/client_test.go +++ b/relayer/pkg/chainlink/ocr2/client_test.go @@ -11,8 +11,7 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo/gateway" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,7 +24,7 @@ const BLOCK_OUTPUT = `{"result": {"events": [ {"from_address": "0xd43963a4e875a3 const ocr2ContractAddress = "0xd43963a4e875a361f5d164b2e70953598eb4f45fde86924082d51b4d78e489" // matches BLOCK_OUTPUT event func TestOCR2Client(t *testing.T) { - chainID := gateway.GOERLI_ID + chainID := "SN_GOERLI" lggr := logger.Test(t) mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -56,24 +55,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, starknetutils.GetSelectorFromNameFelt("latest_transmission_details").String()) + switch reqdata.Selector { + case starknetutils.GetSelectorFromNameFelt("billing").String(): // billing response out = []byte(`{"result":["0x0","0x0","0x0","0x0"]}`) - case caigotypes.BigToHex(caigotypes.GetSelectorFromName("latest_config_details")) == reqdata.Selector: + case starknetutils.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 starknetutils.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 starknetutils.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 starknetutils.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 +98,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..113a1e84e 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/curve" "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 := curve.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 7f53a8411..31e4a29ea 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/libocr/offchainreporting2/reportingplugin/median" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -22,14 +23,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..d05da007b 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" + "github.com/NethermindEth/juno/core/felt" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" + starknetutils "github.com/NethermindEth/starknet.go/utils" "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 // account.publicKey + 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.accountAddress, c.senderAddress, starknetrpc.FunctionCall{ ContractAddress: c.contractAddress, - EntryPointSelector: "transmit", - Calldata: transmitPayload, + EntryPointSelector: starknetutils.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..e0f74fe90 100644 --- a/relayer/pkg/chainlink/ocr2/events_test.go +++ b/relayer/pkg/chainlink/ocr2/events_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/smartcontractkit/libocr/offchainreporting2/types" @@ -61,7 +61,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 +81,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 +95,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 +145,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, starknetutils.GetSelectorFromName("NewTransmission").Cmp(eventKey), 0) } func TestConfigSetEventSelector(t *testing.T) { @@ -152,5 +153,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, starknetutils.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..63686d3b4 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,25 @@ func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types // preserve original array oo = append([]median.ParsedAttributedObservation{}, oo...) - numFelt := caigotypes.BigToFelt(big.NewInt(int64(num))) + numFelt := starknetutils.BigIntToFelt(big.NewInt(int64(num))) // 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 := starknetutils.BigIntToFelt(big.NewInt(int64(timestamp))) // 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 := starknetutils.BigIntToFelt(juelsPerFeeCoin) // TODO: source from observations gasPrice := big.NewInt(1) // := oo[num/2].GasPrice - gasPriceFelt := caigotypes.BigToFelt(gasPrice) + gasPriceFelt := starknetutils.BigIntToFelt(gasPrice) // sort by values sort.Slice(oo, func(i, j int) bool { @@ -69,21 +70,29 @@ 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 := starknetutils.BigIntToFelt(o.Value) + 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 +104,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 +128,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 9f854cd6f..4d4741155 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" + starknetaccount "github.com/NethermindEth/starknet.go/account" "github.com/smartcontractkit/chainlink-common/pkg/loop" adapters "github.com/smartcontractkit/chainlink-common/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 + starknetaccount.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..e8358121c 100644 --- a/relayer/pkg/chainlink/txm/mocks/nonce_manager_client.go +++ b/relayer/pkg/chainlink/txm/mocks/nonce_manager_client.go @@ -4,11 +4,9 @@ package mocks import ( context "context" - big "math/big" + felt "github.com/NethermindEth/juno/core/felt" mock "github.com/stretchr/testify/mock" - - types "github.com/smartcontractkit/caigo/types" ) // NonceManagerClient is an autogenerated mock type for the NonceManagerClient type @@ -17,23 +15,23 @@ 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) (*felt.Felt, error) { ret := _m.Called(_a0, _a1) - var r0 *big.Int + var r0 *felt.Felt 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) (*felt.Felt, 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) *felt.Felt); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) + r0 = ret.Get(0).(*felt.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 4401af81f..85436b3ae 100644 --- a/relayer/pkg/chainlink/txm/nonce.go +++ b/relayer/pkg/chainlink/txm/nonce.go @@ -3,10 +3,9 @@ package txm import ( "context" "fmt" - "math/big" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services" @@ -16,16 +15,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) (*felt.Felt, error) } type NonceManager interface { services.Service - Register(ctx context.Context, address caigotypes.Felt, chainId string, client NonceManagerClient) error + Register(ctx context.Context, address *felt.Felt, publicKey *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) (*felt.Felt, error) + IncrementNextSequence(address *felt.Felt, chainID string, currentNonce *felt.Felt) error } var _ NonceManager = (*nonceManager)(nil) @@ -34,14 +33,14 @@ type nonceManager struct { starter utils.StartStopOnce lggr logger.Logger - n map[string]map[string]*big.Int // map address + chain ID to nonce + n map[string]map[string]*felt.Felt // map address + chain ID to nonce lock sync.RWMutex } func NewNonceManager(lggr logger.Logger) *nonceManager { return &nonceManager{ lggr: logger.Named(lggr, "NonceManager"), - n: map[string]map[string]*big.Int{}, + n: map[string]map[string]*felt.Felt{}, } } @@ -66,12 +65,12 @@ 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, publicKey *felt.Felt, chainId string, client NonceManagerClient) error { nm.lock.Lock() defer nm.lock.Unlock() - addressNonces, exists := nm.n[addr.String()] + addressNonces, exists := nm.n[publicKey.String()] if !exists { - nm.n[addr.String()] = map[string]*big.Int{} + nm.n[publicKey.String()] = map[string]*felt.Felt{} } _, exists = addressNonces[chainId] if !exists { @@ -79,13 +78,13 @@ func (nm *nonceManager) Register(ctx context.Context, addr caigotypes.Felt, chai if err != nil { return err } - nm.n[addr.String()][chainId] = n + nm.n[publicKey.String()][chainId] = n } return nil } -func (nm *nonceManager) NextSequence(addr caigotypes.Felt, chainId string) (*big.Int, error) { +func (nm *nonceManager) NextSequence(addr *felt.Felt, chainId string) (*felt.Felt, error) { if err := nm.validate(addr, chainId); err != nil { return nil, err } @@ -95,7 +94,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 *felt.Felt) error { if err := nm.validate(addr, chainId); err != nil { return err } @@ -106,11 +105,12 @@ func (nm *nonceManager) IncrementNextSequence(addr caigotypes.Felt, chainId stri if n.Cmp(currentNonce) != 0 { return fmt.Errorf("mismatched nonce for %s: %s (expected) != %s (got)", addr, n, currentNonce) } - nm.n[addr.String()][chainId] = big.NewInt(n.Int64() + 1) + one := new(felt.Felt).SetUint64(1) + nm.n[addr.String()][chainId] = new(felt.Felt).Add(n, one) 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 1f9dea0a4..3ccfab00e 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" + "github.com/NethermindEth/juno/core/felt" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" @@ -18,18 +19,19 @@ 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 *felt.Felt) (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(tests.Context(t))) - require.NoError(t, nm.Register(tests.Context(t), keyHash, chainID, c)) + require.NoError(t, nm.Register(tests.Context(t), keyHash, keyHash, chainID, c)) return nm, keyHash, func() { require.NoError(t, nm.Close()) } } @@ -38,7 +40,7 @@ func TestNonceManager_NextSequence(t *testing.T) { t.Parallel() chainId := "test_nextSequence" - initNonce := big.NewInt(10) + initNonce := new(felt.Felt).SetUint64(10) nm, k, stop := newTestNonceManager(t, chainId, initNonce) defer stop() @@ -53,7 +55,7 @@ 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 := starknetutils.BigIntToFelt(big.NewInt(1)) _, 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())) @@ -63,12 +65,13 @@ func TestNonceManager_IncrementNextSequence(t *testing.T) { t.Parallel() chainId := "test_nextSequence" - initNonce := big.NewInt(10) + initNonce := new(felt.Felt).SetUint64(10) nm, k, stop := newTestNonceManager(t, chainId, initNonce) defer stop() - initMinusOne := big.NewInt(initNonce.Int64() - 1) - initPlusOne := big.NewInt(initNonce.Int64() + 1) + one := new(felt.Felt).SetUint64(1) + initMinusOne := new(felt.Felt).Sub(initNonce, one) + initPlusOne := new(felt.Felt).Add(initNonce, one) // should fail if nonce is lower then expected err := nm.IncrementNextSequence(k, chainId, initMinusOne) @@ -88,7 +91,7 @@ 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 := starknetutils.BigIntToFelt(big.NewInt(1)) 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 f3fda3048..8cadf9307 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" @@ -37,7 +37,6 @@ func SetupLocalStarknetNode(t *testing.T) string { cmd := exec.Command("starknet-devnet", "--seed", "0", // use same seed for testing "--port", port, - "--lite-mode", ) var stdErr bytes.Buffer cmd.Stderr = &stdErr @@ -76,9 +75,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 f59d41468..627fd9a3b 100644 --- a/relayer/pkg/chainlink/txm/txm.go +++ b/relayer/pkg/chainlink/txm/txm.go @@ -4,14 +4,14 @@ import ( "context" "errors" "fmt" - "math/big" - "reflect" "sync" "time" - "github.com/smartcontractkit/caigo" - caigorpc "github.com/smartcontractkit/caigo/rpcv02" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" + starknetaccount "github.com/NethermindEth/starknet.go/account" + "github.com/NethermindEth/starknet.go/rpc" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" + starknetutils "github.com/NethermindEth/starknet.go/utils" "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -27,14 +27,14 @@ const ( ) type TxManager interface { - Enqueue(senderAddress caigotypes.Felt, accountAddress caigotypes.Felt, txFn caigotypes.FunctionCall) error + Enqueue(accountAddress *felt.Felt, publicKey *felt.Felt, txFn starknetrpc.FunctionCall) error InflightCount() (int, int) } type Tx struct { - senderAddress caigotypes.Felt - accountAddress caigotypes.Felt - call caigotypes.FunctionCall + publicKey *felt.Felt + accountAddress *felt.Felt + call starknetrpc.FunctionCall } type StarkTXM interface { @@ -114,7 +114,7 @@ func (txm *starktxm) broadcastLoop() { tx := <-txm.queue // broadcast tx serially - wait until accepted by mempool before processing next - hash, err := txm.broadcast(ctx, tx.senderAddress, tx.accountAddress, tx.call) + hash, err := txm.broadcast(ctx, tx.publicKey, tx.accountAddress, tx.call) if err != nil { txm.lggr.Errorw("transaction failed to broadcast", "error", err, "tx", tx.call) } else { @@ -126,15 +126,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, publicKey *felt.Felt, accountAddress *felt.Felt, call starknetrpc.FunctionCall) (txhash string, err error) { 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) + cairoVersion := 2 + account, err := starknetaccount.NewAccount(client.Provider, accountAddress, publicKey.String(), txm.ks, cairoVersion) if err != nil { return txhash, fmt.Errorf("failed to create new account: %+w", err) } @@ -144,47 +144,100 @@ func (txm *starktxm) broadcast(ctx context.Context, senderAddress caigotypes.Fel return txhash, fmt.Errorf("failed to get chainID: %+w", err) } - nonce, err := txm.nonce.NextSequence(accountAddress, chainID) + nonce, err := txm.nonce.NextSequence(publicKey, chainID) if err != nil { return txhash, fmt.Errorf("failed to get nonce: %+w", err) } - // get fee for txm + // TODO: update to v3 + + // maxfee, err := starknetutils.HexToFelt("0x95e566845d000") + // if err != nil { + // return txhash, err + // } + + // Building the tx struct + tx := starknetrpc.InvokeTxnV3{ + Type: starknetrpc.TransactionType_Invoke, + SenderAddress: account.AccountAddress, + Version: starknetrpc.TransactionV3, + Signature: []*felt.Felt{}, + Nonce: nonce, + ResourceBounds: starknetrpc.ResourceBoundsMapping{ // TODO: use proper values + L1Gas: starknetrpc.ResourceBounds{ + MaxAmount: "0x186a0", + MaxPricePerUnit: "0x5af3107a4000", + }, + L2Gas: starknetrpc.ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, + }, + Tip: "0x0", + PayMasterData: []*felt.Felt{}, + AccountDeploymentData: []*felt.Felt{}, + NonceDataMode: rpc.DAModeL1, // TODO: confirm + FeeMode: rpc.DAModeL1, // TODO: confirm + } + + // Building the Calldata with the help of FmtCalldata where we pass in the FnCall struct along with the Cairo version + tx.Calldata, err = account.FmtCalldata([]starknetrpc.FunctionCall{call}) + if err != nil { + return txhash, err + } + + // TODO: if we estimate with sig then the hash changes and we have to re-sign + // if we don't then the signature is invalid?? + + // get fee for tx // 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{}) + // simFlags := []starknetrpc.SimulationFlag{} + // feeEstimate, err := account.EstimateFee(ctx, []starknetrpc.BroadcastTxn{tx}, simFlags, starknetrpc.BlockID{Tag: "latest"}) + // if err != nil { + // return txhash, fmt.Errorf("failed to estimate fee: %+w", err) + // } + // expandedFee := new(felt.Felt).Mul(feeEstimate[0].OverallFee, FEE_MARGIN) + // maxfee = new(felt.Felt).Div(expandedFee, new(felt.Felt).SetUint64(100)) + // tx.MaxFee = feeEstimate[0].OverallFee // TODO: mul times margin + + // Signing of the transaction that is done by the account + // TODO: SignInvokeTransaction for V3 is missing so we do it by hand + // err = account.SignInvokeTransaction(context.Background(), &tx) + // if err != nil { + // return txhash, fmt.Errorf("failed to sign tx: %+w", err) + // } + hash, err := account.TransactionHashInvoke(tx) if err != nil { - return txhash, fmt.Errorf("failed to estimate fee: %+w", err) + return txhash, err } - - 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{ - MaxFee: max, - Nonce: nonce, + signature, err := account.Sign(ctx, hash) + if err != nil { + return txhash, err } + tx.Signature = signature - // transmit txs execCtx, execCancel := context.WithTimeout(ctx, txm.cfg.TxTimeout()) defer execCancel() - res, err := account.Execute(execCtx, txs, details) + + // finally, transmit the invoke + res, err := account.AddInvokeTransaction(execCtx, tx) if err != nil { // TODO: handle initial broadcast errors - what kind of errors occur? return txhash, fmt.Errorf("failed to invoke tx: %+w", err) } - // handle nil pointer if res == nil { return txhash, errors.New("execute response and error are nil") } // update nonce if transaction is successful + txhash = res.TransactionHash.String() err = errors.Join( - txm.nonce.IncrementNextSequence(accountAddress, chainID, nonce), - txm.txStore.Save(accountAddress, nonce, res.TransactionHash), + txm.nonce.IncrementNextSequence(publicKey, chainID, nonce), + txm.txStore.Save(accountAddress, nonce, txhash), ) - return res.TransactionHash, err + return txhash, err } func (txm *starktxm) confirmLoop() { @@ -211,20 +264,21 @@ 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("failed to fetch transaction status", "hash", hash, "error", err) + txm.lggr.Errorw("invalid felt value", "hash", hash) continue } - receipt, ok := response.(caigorpc.InvokeTransactionReceipt) - if !ok { - txm.lggr.Errorw("wrong receipt type", "type", reflect.TypeOf(response)) + response, err := client.Provider.GetTransactionStatus(ctx, f) + if err != nil { + txm.lggr.Errorw("failed to fetch transaction status", "hash", hash, "error", err) continue } - status := receipt.Status + status := response.FinalityStatus - if status == caigotypes.TransactionAcceptedOnL1 || status == caigotypes.TransactionAcceptedOnL2 || status == caigotypes.TransactionRejected { + // any status other than received + if status == starknetrpc.TxnStatus_Accepted_On_L1 || status == starknetrpc.TxnStatus_Accepted_On_L2 || status == starknetrpc.TxnStatus_Rejected { 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) @@ -261,13 +315,13 @@ 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(accountAddress, publicKey *felt.Felt, tx starknetrpc.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 // existence of a key - if _, err := txm.ks.Loopp().Sign(context.Background(), senderAddress.String(), nil); err != nil { - return err + if _, err := txm.ks.Loopp().Sign(context.Background(), publicKey.String(), nil); err != nil { + return fmt.Errorf("enqueue: failed to sign: %+w", err) } client, err := txm.client.Get() @@ -282,12 +336,12 @@ func (txm *starktxm) Enqueue(senderAddress, accountAddress caigotypes.Felt, tx c } // register account for nonce manager - if err := txm.nonce.Register(context.TODO(), accountAddress, chainID, client); err != nil { - return err + if err := txm.nonce.Register(context.TODO(), accountAddress, publicKey, chainID, client); err != nil { + return fmt.Errorf("failed to register nonce: %+w", err) } select { - case txm.queue <- Tx{senderAddress: senderAddress, accountAddress: accountAddress, call: tx}: + case txm.queue <- Tx{publicKey: publicKey, accountAddress: accountAddress, call: tx}: // TODO fix naming here default: return fmt.Errorf("failed to enqueue transaction: %+v", tx) } diff --git a/relayer/pkg/chainlink/txm/txm_test.go b/relayer/pkg/chainlink/txm/txm_test.go index fbea54a1a..08146c56b 100644 --- a/relayer/pkg/chainlink/txm/txm_test.go +++ b/relayer/pkg/chainlink/txm/txm_test.go @@ -9,10 +9,10 @@ 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/curve" + "github.com/NethermindEth/starknet.go/devnet" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" @@ -26,34 +26,41 @@ import ( func TestIntegration_Txm(t *testing.T) { n := 2 // number of txs per key - url := SetupLocalStarknetNode(t) - devnet := test.NewDevNet(url) + // url := SetupLocalStarknetNode(t) + url := "http://127.0.0.1:5050" + devnet := devnet.NewDevNet(url) accounts, err := devnet.Accounts() require.NoError(t, err) + fmt.Println("qqq") // parse keys into expected format - localKeys := map[string]*big.Int{} - localAccounts := map[string]string{} + type Key struct { + PrivateKey *big.Int + Account string + } + localKeys := map[string]Key{} for i := range accounts { - privKey, err := caigotypes.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 + publicKey := accounts[i].PublicKey + fmt.Printf("account %v pubkey %v\n", accounts[i].Address, publicKey) + localKeys[publicKey] = Key{ + PrivateKey: starknetutils.HexToBN(accounts[i].PrivateKey), + Account: accounts[i].Address, + } } // mock keystore - looppKs := NewLooppKeystore(func(id string) (*big.Int, error) { - _, ok := localKeys[id] + looppKs := NewLooppKeystore(func(publicKey string) (*big.Int, error) { + key, ok := localKeys[publicKey] if !ok { - return nil, fmt.Errorf("key does not exist id=%s", id) + return nil, fmt.Errorf("key does not exist id=%s", publicKey) } - return localKeys[id], nil + return key.PrivateKey, 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("SN_GOERLI", url+"/rpc", lggr, &timeout) require.NoError(t, err) getClient := func() (*starknet.Client, error) { @@ -74,18 +81,29 @@ func TestIntegration_Txm(t *testing.T) { // start txm + checks require.NoError(t, txm.Start(context.Background())) require.NoError(t, txm.Ready()) + fmt.Println("sss") + + for publicKeyStr := range localKeys { + publicKey, err := starknetutils.HexToFelt(publicKeyStr) + require.NoError(t, err) + + accountAddress, err := starknetutils.HexToFelt(localKeys[publicKeyStr].Account) + require.NoError(t, err) + + contractAddress, err := starknetutils.HexToFelt("0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7") + require.NoError(t, err) + + selector := starknetutils.GetSelectorFromNameFelt("totalSupply") - for senderAddressStr := range localKeys { - senderAddress := caigotypes.StrToFelt(senderAddressStr) 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(accountAddress, publicKey, starknetrpc.FunctionCall{ + ContractAddress: contractAddress, // send to ETH token contract + EntryPointSelector: selector, })) } } var empty bool - for i := 0; i < 60; i++ { + for i := 0; i < 30; i++ { time.Sleep(500 * time.Millisecond) queued, unconfirmed := txm.InflightCount() accepted := len(observer.FilterMessageSnippet("ACCEPTED_ON_L2").All()) @@ -135,7 +153,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 := curve.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..d56a2bafb 100644 --- a/relayer/pkg/chainlink/txm/txstore.go +++ b/relayer/pkg/chainlink/txm/txstore.go @@ -2,52 +2,52 @@ package txm import ( "fmt" - "math/big" "sync" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "golang.org/x/exp/maps" ) // TxStore tracks broadcast & unconfirmed txs type TxStore struct { lock sync.RWMutex - nonceToHash map[int64]string // map nonce to txhash - hashToNonce map[string]int64 // map hash to nonce - currentNonce *big.Int // minimum nonce + nonceToHash map[felt.Felt]string // map nonce to txhash + hashToNonce map[string]felt.Felt // map hash to nonce + currentNonce felt.Felt // minimum nonce } -func NewTxStore(current *big.Int) *TxStore { +func NewTxStore(current *felt.Felt) *TxStore { return &TxStore{ - nonceToHash: map[int64]string{}, - hashToNonce: map[string]int64{}, - currentNonce: current, + nonceToHash: map[felt.Felt]string{}, + hashToNonce: map[string]felt.Felt{}, + currentNonce: *current, } } -func (s *TxStore) Save(nonce *big.Int, hash string) error { +// TODO: Save should make a copy otherwise wee're modiffying the same memory and could loop +func (s *TxStore) Save(nonce *felt.Felt, hash string) error { s.lock.Lock() defer s.lock.Unlock() if s.currentNonce.Cmp(nonce) == 1 { - return fmt.Errorf("nonce too low: %s < %s (lowest)", nonce, s.currentNonce) + return fmt.Errorf("nonce too low: %s < %s (lowest)", nonce, &s.currentNonce) } - if h, exists := s.nonceToHash[nonce.Int64()]; exists { + if h, exists := s.nonceToHash[*nonce]; exists { return fmt.Errorf("nonce used: tried to use nonce (%s) for tx (%s), already used by (%s)", nonce, hash, h) } if n, exists := s.hashToNonce[hash]; exists { - return fmt.Errorf("hash used: tried to use tx (%s) for nonce (%s), already used nonce (%d)", hash, nonce, n) + return fmt.Errorf("hash used: tried to use tx (%s) for nonce (%s), already used nonce (%s)", hash, nonce, &n) } // store hash - s.nonceToHash[nonce.Int64()] = hash - s.hashToNonce[hash] = nonce.Int64() + s.nonceToHash[*nonce] = hash + s.hashToNonce[hash] = *nonce // find next unused nonce - _, exists := s.nonceToHash[s.currentNonce.Int64()] + _, exists := s.nonceToHash[s.currentNonce] for exists { - s.currentNonce.Add(s.currentNonce, big.NewInt(1)) - _, exists = s.nonceToHash[s.currentNonce.Int64()] + s.currentNonce = *new(felt.Felt).Add(&s.currentNonce, new(felt.Felt).SetUint64(1)) + _, exists = s.nonceToHash[s.currentNonce] } return nil } @@ -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 *felt.Felt, 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..3c7f500d5 100644 --- a/relayer/pkg/chainlink/txm/txstore_test.go +++ b/relayer/pkg/chainlink/txm/txstore_test.go @@ -3,11 +3,10 @@ package txm import ( "errors" "fmt" - "math/big" "sync" "testing" - caigotypes "github.com/smartcontractkit/caigo/types" + "github.com/NethermindEth/juno/core/felt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -18,9 +17,9 @@ func TestTxStore(t *testing.T) { t.Run("happypath", func(t *testing.T) { t.Parallel() - s := NewTxStore(big.NewInt(0)) + s := NewTxStore(&felt.Zero) assert.Equal(t, 0, s.InflightCount()) - require.NoError(t, s.Save(big.NewInt(0), "0x0")) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(0), "0x0")) assert.Equal(t, 1, s.InflightCount()) assert.Equal(t, []string{"0x0"}, s.GetUnconfirmed()) require.NoError(t, s.Confirm("0x0")) @@ -32,38 +31,38 @@ func TestTxStore(t *testing.T) { t.Parallel() // create - s := NewTxStore(big.NewInt(0)) + s := NewTxStore(new(felt.Felt).SetUint64(0)) // accepts tx in order - require.NoError(t, s.Save(big.NewInt(0), "0x0")) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(0), "0x0")) assert.Equal(t, 1, s.InflightCount()) - assert.Equal(t, int64(1), s.currentNonce.Int64()) + assert.Equal(t, new(felt.Felt).SetUint64(1), &s.currentNonce) // accepts tx that skips a nonce - require.NoError(t, s.Save(big.NewInt(2), "0x2")) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(2), "0x2")) assert.Equal(t, 2, s.InflightCount()) - assert.Equal(t, int64(1), s.currentNonce.Int64()) + assert.Equal(t, new(felt.Felt).SetUint64(1), &s.currentNonce) // accepts tx that fills in the missing nonce + fast forwards currentNonce - require.NoError(t, s.Save(big.NewInt(1), "0x1")) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(1), "0x1")) assert.Equal(t, 3, s.InflightCount()) - assert.Equal(t, int64(3), s.currentNonce.Int64()) + assert.Equal(t, new(felt.Felt).SetUint64(3), &s.currentNonce) // skip a nonce for later tests - require.NoError(t, s.Save(big.NewInt(4), "0x4")) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(4), "0x4")) assert.Equal(t, 4, s.InflightCount()) - assert.Equal(t, int64(3), s.currentNonce.Int64()) + assert.Equal(t, new(felt.Felt).SetUint64(3), &s.currentNonce) // rejects old nonce - require.ErrorContains(t, s.Save(big.NewInt(0), "0xold"), "nonce too low: 0 < 3 (lowest)") + require.ErrorContains(t, s.Save(new(felt.Felt).SetUint64(0), "0xold"), "nonce too low: 0x0 < 0x3 (lowest)") assert.Equal(t, 4, s.InflightCount()) // reject already in use nonce - require.ErrorContains(t, s.Save(big.NewInt(4), "0xskip"), "nonce used: tried to use nonce (4) for tx (0xskip), already used by (0x4)") + require.ErrorContains(t, s.Save(new(felt.Felt).SetUint64(4), "0xskip"), "nonce used: tried to use nonce (0x4) for tx (0xskip), already used by (0x4)") assert.Equal(t, 4, s.InflightCount()) // reject already in use tx hash - require.ErrorContains(t, s.Save(big.NewInt(5), "0x0"), "hash used: tried to use tx (0x0) for nonce (5), already used nonce (0)") + require.ErrorContains(t, s.Save(new(felt.Felt).SetUint64(5), "0x0"), "hash used: tried to use tx (0x0) for nonce (0x5), already used nonce (0x0)") assert.Equal(t, 4, s.InflightCount()) // race save @@ -72,11 +71,11 @@ func TestTxStore(t *testing.T) { var wg sync.WaitGroup wg.Add(2) go func() { - err0 = s.Save(big.NewInt(10), "0x10") + err0 = s.Save(new(felt.Felt).SetUint64(10), "0x10") wg.Done() }() go func() { - err1 = s.Save(big.NewInt(10), "0x10") + err1 = s.Save(new(felt.Felt).SetUint64(10), "0x10") wg.Done() }() wg.Wait() @@ -87,9 +86,9 @@ func TestTxStore(t *testing.T) { t.Parallel() // init store - s := NewTxStore(big.NewInt(0)) + s := NewTxStore(new(felt.Felt).SetUint64(0)) for i := 0; i < 5; i++ { - require.NoError(t, s.Save(big.NewInt(int64(i)), "0x"+fmt.Sprintf("%d", i))) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(uint64(i)), "0x"+fmt.Sprintf("%d", i))) } // confirm in order @@ -108,7 +107,7 @@ func TestTxStore(t *testing.T) { require.ErrorContains(t, s.Confirm("0xNULL"), "tx hash does not exist - it may already be confirmed") // race confirm - require.NoError(t, s.Save(big.NewInt(10), "0x10")) + require.NoError(t, s.Save(new(felt.Felt).SetUint64(10), "0x10")) var err0 error var err1 error var wg sync.WaitGroup @@ -131,36 +130,39 @@ func TestChainTxStore(t *testing.T) { c := NewChainTxStore() + felt0 := new(felt.Felt).SetUint64(0) + felt1 := new(felt.Felt).SetUint64(1) + // automatically save the from address - require.NoError(t, c.Save(caigotypes.Felt{}, big.NewInt(0), "0x0")) + require.NoError(t, c.Save(felt0, new(felt.Felt).SetUint64(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(felt0, new(felt.Felt).SetUint64(0), "0x1")) + assert.Error(t, c.Save(felt0, new(felt.Felt).SetUint64(1), "0x0")) // inflight count - count, exists := c.GetAllInflightCount()[caigotypes.Felt{}] + count, exists := c.GetAllInflightCount()[felt0] 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[felt0] 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(felt0, "0x0")) + assert.ErrorContains(t, c.Confirm(felt1, "0x0"), "from address does not exist") + assert.Error(t, c.Confirm(felt0, "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[felt0])) + count, exists = c.GetAllInflightCount()[felt0] assert.True(t, exists) assert.Equal(t, 0, count) } diff --git a/relayer/pkg/starknet/client.go b/relayer/pkg/starknet/client.go index aa50ef473..02de45433 100644 --- a/relayer/pkg/starknet/client.go +++ b/relayer/pkg/starknet/client.go @@ -2,15 +2,14 @@ package starknet import ( "context" - "math/big" "time" "github.com/pkg/errors" + "github.com/NethermindEth/juno/core/felt" + starknetaccount "github.com/NethermindEth/starknet.go/account" + starknetrpc "github.com/NethermindEth/starknet.go/rpc" ethrpc "github.com/ethereum/go-ethereum/rpc" - "github.com/smartcontractkit/caigo" - caigorpc "github.com/smartcontractkit/caigo/rpcv02" - caigotypes "github.com/smartcontractkit/caigo/types" "github.com/smartcontractkit/chainlink-common/pkg/logger" ) @@ -18,16 +17,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) (*felt.Felt, error) } type Writer interface { @@ -40,10 +39,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.RpcProvider lggr logger.Logger defaultTimeout time.Duration } @@ -57,7 +56,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 +73,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 +105,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 +114,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 +137,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 +155,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 +173,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,17 +190,18 @@ 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) (*felt.Felt, 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() - account, err := caigo.NewRPCAccount(sender, accountAddress, nil, c.Provider, caigo.AccountVersion1) + sender := &felt.Zero // not actually used in account.Nonce() + cairoVersion := 2 + account, err := starknetaccount.NewAccount(c.Provider, accountAddress, sender.String(), nil, cairoVersion) if err != nil { return nil, errors.Wrap(err, "error in client.AccountNonce") } - return account.Nonce(ctx) + return account.Nonce(ctx, starknetrpc.BlockID{Tag: "latest"}, account.AccountAddress) } diff --git a/relayer/pkg/starknet/client_test.go b/relayer/pkg/starknet/client_test.go index 45af3f54b..e3d88b24a 100644 --- a/relayer/pkg/starknet/client_test.go +++ b/relayer/pkg/starknet/client_test.go @@ -10,8 +10,7 @@ import ( "testing" "time" - "github.com/smartcontractkit/caigo/gateway" - caigotypes "github.com/smartcontractkit/caigo/types" + starknetutils "github.com/NethermindEth/starknet.go/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -19,7 +18,7 @@ import ( ) var ( - chainID = gateway.GOERLI_ID + chainID = "SN_GOERLI" timeout = 10 * time.Second ) @@ -40,12 +39,12 @@ func TestRPCClient(t *testing.T) { switch call.Method { case "starknet_chainId": - id := caigotypes.BigToHex(caigotypes.UTF8StrToBig(chainID)) + id := starknetutils.BigToHex(starknetutils.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..cb88175c1 100644 --- a/relayer/pkg/starknet/mocks/Reader.go +++ b/relayer/pkg/starknet/mocks/Reader.go @@ -4,15 +4,13 @@ package mocks 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,23 +19,23 @@ 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) (*felt.Felt, error) { ret := _m.Called(_a0, _a1) - var r0 *big.Int + var r0 *felt.Felt 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) (*felt.Felt, 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) *felt.Felt); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) + r0 = ret.Get(0).(*felt.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) @@ -47,23 +45,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 +71,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 +97,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 +123,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 +173,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 +199,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) diff --git a/shell.nix b/shell.nix index 4fb605bef..0743e2678 100644 --- a/shell.nix +++ b/shell.nix @@ -5,12 +5,6 @@ buildInputs = with pkgs; [ stdenv.cc.cc.lib (rust-bin.stable.latest.default.override { extensions = ["rust-src"]; }) - python39 - python39Packages.pip - python39Packages.venvShellHook - python39Packages.fastecdsa # so libgmp is correctly sourced - zlib # for numpy - gmp nodejs-18_x (yarn.override { nodejs = nodejs-18_x; }) nodePackages.typescript @@ -36,6 +30,4 @@ LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.zlib stdenv.cc.cc.lib]; # lib64 HELM_REPOSITORY_CONFIG = "./.helm-repositories.yaml"; - - venvDir = "./.venv"; }