From 4c6911c52c1a675cc83d099ad2260a7849009868 Mon Sep 17 00:00:00 2001 From: Augustus <14297860+augustbleeds@users.noreply.github.com> Date: Mon, 26 Feb 2024 23:19:22 -0500 Subject: [PATCH] working stom changes (#361) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Blaž Hrastnik --- .tool-versions | 2 +- monitoring/pkg/monitoring/source_envelope.go | 6 +++--- monitoring/pkg/monitoring/source_envelope_test.go | 2 +- relayer/pkg/chainlink/ocr2/client.go | 11 +++++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.tool-versions b/.tool-versions index be2e95640..7533e0973 100644 --- a/.tool-versions +++ b/.tool-versions @@ -10,7 +10,7 @@ golangci-lint 1.55.0 actionlint 1.6.12 shellcheck 0.8.0 scarb 2.5.4 -postgres 13.3 +postgres 15.1 # Kubernetes k3d 5.4.4 diff --git a/monitoring/pkg/monitoring/source_envelope.go b/monitoring/pkg/monitoring/source_envelope.go index 323bdf788..5d833eb77 100644 --- a/monitoring/pkg/monitoring/source_envelope.go +++ b/monitoring/pkg/monitoring/source_envelope.go @@ -168,14 +168,14 @@ var zeroBigInt = big.NewInt(0) 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: starknetutils.GetSelectorFromNameFelt("balanceOf"), + Selector: starknetutils.GetSelectorFromNameFelt("balance_of"), Calldata: []*felt.Felt{contractAddress}, }) if err != nil { - return nil, fmt.Errorf("failed call to ECR20 contract, balanceOf method: %w", err) + return nil, fmt.Errorf("failed call to ECR20 contract, balance_of method: %w", err) } if len(results) < 1 { - return nil, fmt.Errorf("insufficient data from balanceOf '%v': %w", results, err) + return nil, fmt.Errorf("insufficient data from balance_of '%v': %w", results, err) } linkBalance := results[0].BigInt(big.NewInt(0)) if linkBalance.Cmp(zeroBigInt) == 0 { diff --git a/monitoring/pkg/monitoring/source_envelope_test.go b/monitoring/pkg/monitoring/source_envelope_test.go index 0833f37c5..dfb9b7034 100644 --- a/monitoring/pkg/monitoring/source_envelope_test.go +++ b/monitoring/pkg/monitoring/source_envelope_test.go @@ -63,7 +63,7 @@ func TestEnvelopeSource(t *testing.T) { mock.Anything, // ctx starknet.CallOps{ ContractAddress: chainConfig.GetLinkTokenAddress(), - Selector: "balanceOf", + Selector: "balance_of", Calldata: []string{ starknetutils.HexToBN(feedConfig.ContractAddress).String(), }, diff --git a/relayer/pkg/chainlink/ocr2/client.go b/relayer/pkg/chainlink/ocr2/client.go index abcc6c112..ecfff3459 100644 --- a/relayer/pkg/chainlink/ocr2/client.go +++ b/relayer/pkg/chainlink/ocr2/client.go @@ -173,10 +173,17 @@ func (c *Client) LinkAvailableForPayment(ctx context.Context, address *felt.Felt if err != nil { return nil, errors.Wrap(err, "failed to call the contract with selector 'link_available_for_payment'") } - if len(results) != 1 { + if len(results) != 2 { return nil, errors.Wrap(err, "insufficient data from selector 'link_available_for_payment'") } - return results[0].BigInt(big.NewInt(0)), nil + + isNegative := !results[0].IsZero() + ans := results[1].BigInt(big.NewInt(0)) + if isNegative { + ans.Neg(ans) + } + + return ans, nil } func (c *Client) fetchEventsFromBlock(ctx context.Context, address *felt.Felt, eventType string, blockNum uint64) (eventsAsFeltArrs [][]*felt.Felt, err error) {