-
Notifications
You must be signed in to change notification settings - Fork 2
Fix ton accessor GetFeeQuoterTokenUpdates #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
5ea0ce1
2c5ebf6
f149871
feefd7a
4e94454
4c7cec5
c2f0703
85887d5
c432910
18a750e
66dac84
20416f7
4694357
00090bf
875ffdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -480,11 +480,13 @@ func FetchResultHelper( | |
| } else { | ||
| result, err = client.RunGetMethod(ctx, block, contractAddr, method, opts...) | ||
| } | ||
|
|
||
|
||
| if err != nil { | ||
| return fmt.Errorf("error getting %s: %w", method, err) | ||
| return err | ||
| } | ||
|
|
||
| if err = fromResult(result); err != nil { | ||
| return fmt.Errorf("failed to parse %s: %w", method, err) | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ import ( | |
| "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-ton/pkg/ccip/bindings/common" | ||
| "github.com/smartcontractkit/chainlink-ton/pkg/ccip/bindings/feequoter" | ||
| "github.com/smartcontractkit/chainlink-ton/pkg/ccip/bindings/ocr" | ||
| "github.com/smartcontractkit/chainlink-ton/pkg/ccip/bindings/offramp" | ||
|
|
@@ -263,7 +262,7 @@ func (a *TONAccessor) LatestMessageTo(ctx context.Context, dest ccipocr3.ChainSe | |
| SkipBytes(40). // Skip to DestChainSelector | ||
| FilterBytes(8, query.EQ(binary.BigEndian.AppendUint64(nil, uint64(dest)))). | ||
| OrderBy(query.SortByTxLT, query.DESC). // sort by transaction LT new to old | ||
| Limit(1). // only get the last one | ||
| Limit(1). // only get the last one | ||
| Execute(ctx, a.logPoller.GetStore()) | ||
|
|
||
| if err != nil { | ||
|
|
@@ -648,7 +647,8 @@ func (a *TONAccessor) GetChainFeePriceUpdate(ctx context.Context, selectors []cc | |
| for _, selector := range selectors { | ||
| result, err := a.client.RunGetMethod(ctx, block, addr, "destinationChainGasPrice", uint64(selector)) | ||
| // The plugin is built with EVM behaviour in mind: if a value doesn't exist the zero value is returned | ||
| if execError, ok := err.(ton.ContractExecError); ok && execError.Code == common.ErrUnknownDestChainSelector { //nolint:errorlint // we're guaranteed to get unwrapped error here | ||
| if execError, ok := err.(ton.ContractExecError); ok && execError.Code == 24814 { //nolint:errorlint // we're guaranteed to get unwrapped error here | ||
|
||
| // TODO remove hard coded error code for UnknownDestChainSelector, right now common.UnknownDestChainSelector doesn't match with on-chain | ||
| prices[selector] = ccipocr3.TimestampedUnixBig{ | ||
| Timestamp: 0, | ||
| Value: big.NewInt(0), | ||
|
|
@@ -720,6 +720,8 @@ func (a *TONAccessor) GetFeeQuoterTokenUpdates( | |
| ctx context.Context, | ||
| tokens []ccipocr3.UnknownAddress, | ||
| ) (map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig, error) { | ||
| // NOTE: Currently, input tokens are mostly LINK and the native token, so batching is not implemented | ||
| // to keep the TON accessor simple. Batching can be added later if needed, such as for performance bottlenecks. | ||
| addr, err := a.getBinding(consts.ContractNameFeeQuoter) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -730,8 +732,7 @@ func (a *TONAccessor) GetFeeQuoterTokenUpdates( | |
| } | ||
|
|
||
| // TODO: decode token addresses here according to chain selector | ||
|
|
||
| encodedTokens := make([]any, 0, len(tokens)) | ||
| prices := make(map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig, len(tokens)) | ||
| for _, token := range tokens { | ||
| strAddr, err2 := a.addrCodec.AddressBytesToString(token) | ||
| if err2 != nil { | ||
|
|
@@ -741,40 +742,27 @@ func (a *TONAccessor) GetFeeQuoterTokenUpdates( | |
| if err2 != nil { | ||
| return nil, fmt.Errorf("failed to ParseAddr %s for encodedTokens: %w", strAddr, err2) | ||
| } | ||
| encodedTokens = append(encodedTokens, addrParsed) | ||
| } | ||
| result, err := a.client.RunGetMethod(ctx, block, addr, "tokenPrices", encodedTokens...) | ||
| // result is a list of TimestampedPrice | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| results := result.AsTuple() | ||
| if len(tokens) != len(results) { | ||
| return nil, fmt.Errorf("length mismatch: expected %d prices but received %d", len(tokens), len(results)) | ||
| } | ||
| prices := make(map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig, len(tokens)) | ||
| for i, priceResult := range results { | ||
| token := tokens[i] | ||
| var price ccipocr3.TimestampedUnixBig | ||
| switch priceResult := priceResult.(type) { | ||
| case nil: | ||
| // return zero value | ||
| price = ccipocr3.TimestampedUnixBig{ | ||
| Value: big.NewInt(0), | ||
| Timestamp: 0, | ||
| } | ||
| case cell.Cell: | ||
|
Comment on lines
-760
to
-766
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not need to explicitly handle this case anymore?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I'm adding that but I notice the contact mustGet is not retuning the right error code but returned stack underflow, checking what's going on |
||
| var timestampedPrice feequoter.TimestampedPrice | ||
| if err := tlb.LoadFromCell(×tampedPrice, priceResult.BeginParse()); err != nil { | ||
| return nil, err | ||
| } | ||
| price = ccipocr3.TimestampedUnixBig{ | ||
| Value: timestampedPrice.Value, | ||
| Timestamp: timestampedPrice.Timestamp, | ||
|
|
||
| var tokenPrice feequoter.TimestampedPrice | ||
| err = tokenPrice.FetchResult(ctx, a.client, block, addr, []interface{}{cell.BeginCell().MustStoreAddr(addrParsed).EndCell().BeginParse()}) | ||
|
Comment on lines
+746
to
+747
|
||
| if err != nil { | ||
| // The plugin is built with EVM behaviour in mind: if a value doesn't exist the zero value is returned | ||
| if execError, ok := err.(ton.ContractExecError); ok && execError.Code == 24813 { // nolint:errorlint // we're guaranteed to get unwrapped error here | ||
| // TODO remove hard coded error code for TokenNotSupported, right now common.TokenNotSupported doesn't match with on-chain | ||
| prices[ccipocr3.UnknownEncodedAddress(token)] = ccipocr3.TimestampedUnixBig{ | ||
| Timestamp: 0, | ||
| Value: big.NewInt(0), | ||
| } | ||
| continue | ||
| } | ||
| default: | ||
| return nil, fmt.Errorf("expected either cell or nil, received %T", priceResult) | ||
| return nil, fmt.Errorf("failed to FetchResult for encodedTokens: %w", err) | ||
| } | ||
|
|
||
| price := ccipocr3.TimestampedUnixBig{ | ||
| Value: tokenPrice.Value, | ||
| Timestamp: tokenPrice.Timestamp, | ||
| } | ||
|
|
||
| if !utf8.ValidString(token.String()) { | ||
| return nil, fmt.Errorf("gRPC can't handle non-UTF8 strings: %x", token) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing this stack underflow issue https://chainlink-core.slack.com/archives/C08KVCWAZUG/p1761932964876469