Skip to content

[OPDATA-6166] Returning calculated-multi-function as a decimal with no scalar#4787

Closed
chray-zhang wants to merge 4 commits intomainfrom
cz/opdata-6166-view-function-decimal
Closed

[OPDATA-6166] Returning calculated-multi-function as a decimal with no scalar#4787
chray-zhang wants to merge 4 commits intomainfrom
cz/opdata-6166-view-function-decimal

Conversation

@chray-zhang
Copy link
Copy Markdown
Collaborator

@chray-zhang chray-zhang commented Mar 31, 2026

Closes OPDATA-6166

Description

  • Added decimal support to decode hex to decimal and return decimal results as well as decimal places

Steps to Test

curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "endpoint": "calculated-multi-function",
      "functionCalls": [
        {
        "name": "result",
        "address": "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497",
        "inputParams": [
          "1000000000000000000"
        ],
        "network": "ethereum",
        "resultField": "price",
        "signature": "function previewRedeem(uint256) external view returns (uint256 price)",
        "decimals": 0
      }
      ],
      "aptosCalls": [],
      "constants": [],
      "operations": []
    }
  }' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1123  100   591  100   532    416    374  0:00:01  0:00:01 --:--:--   790
{
  "data": {
    "result": "1225619006177976307"
  },
  "statusCode": 200,
  "result": "1225619006177976307",
  "timestamps": {
    "providerDataRequestedUnixMs": 1774979153846,
    "providerDataReceivedUnixMs": 1774979154301
  },
  "meta": {
    "adapterName": "VIEW_FUNCTION_MULTI_CHAIN",
    "metrics": {
      "feedId": "{\"functionCalls\":[{\"name\":\"result\",\"signature\":\"function previewredeem(uint256) external view returns (uint256 price)\",\"address\":\"0x9d39a5de30e57443bff2a8307a4256c8797a3497\",\"inputParams\":[\"1000000000000000000\"],\"network\":\"ethereum\",\"decimals\":0}],\"aptosCalls\":[],\"constants\":[],\"operations\":[]}"
    }
  }
}

Quality Assurance

  • [x ] If a new adapter was made, or an existing one was modified so that its environment variables have changed, update the relevant infra-k8s configuration file.
  • [x ] If a new adapter was made, or an existing one was modified so that its environment variables have changed, update the relevant adapter-secrets configuration file.
  • [x ] If a new adapter was made, or a new endpoint was added, update the test-payload.json file with relevant requests.
  • [x ] The branch naming follows git flow (feature/x, chore/x, release/x, hotfix/x, fix/x) or is created from Jira.
  • [x ] This is related to a maximum of one Jira story or GitHub issue.
  • [x ] Types are safe (avoid TypeScript/TSLint features like any and disable, instead use more specific types).
  • [x ] All code changes have 100% unit and integration test coverage. If testing is not applicable or too difficult to justify doing, the reasoning should be documented explicitly in the PR.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

🦋 Changeset detected

Latest commit: ebbc179

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@chainlink/view-function-multi-chain-adapter Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chray-zhang chray-zhang marked this pull request as ready for review April 1, 2026 03:39
@danwilliams-cll danwilliams-cll requested a review from Copilot April 1, 2026 12:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional decimal scaling support to the calculated-multi-function endpoint in the view-function multi-chain adapter, changing how EVM call results are decoded/returned.

Changes:

  • Added optional decimals input to scale single-return EVM results using ethers.formatUnits.
  • Updated transport to decode single-return function outputs into decimal strings (and keep raw hex for multi-return).
  • Added integration tests + snapshot updates and a changeset entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/sources/view-function-multi-chain/src/transport/calculated-multi-function.ts Decodes EVM call results; adds decimal scaling logic and changes single-output return format.
packages/sources/view-function-multi-chain/src/endpoint/calculated-multi-function.ts Adds decimals as an optional request parameter for function calls.
packages/sources/view-function-multi-chain/test/integration/adapter.test.ts Adds integration tests for decimals scaling and decimals=0 behavior.
packages/sources/view-function-multi-chain/test/integration/snapshots/adapter.test.ts.snap Updates snapshots to reflect decoded decimal output and new decimals-scaling cases.
.changeset/jolly-maps-cross.md Declares a version bump for the adapter package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dskloetc
Copy link
Copy Markdown
Contributor

dskloetc commented Apr 1, 2026

Do we need this? Can't we just multiply?

@chray-zhang chray-zhang changed the title [OPDATA-6166] Cz/opdata 6166 view function decimal [OPDATA-6166] Returning calculated-multi-function as a decimal with no scaler Apr 1, 2026
@chray-zhang chray-zhang changed the title [OPDATA-6166] Returning calculated-multi-function as a decimal with no scaler [OPDATA-6166] Returning calculated-multi-function as a decimal with no scalar Apr 1, 2026
@chray-zhang chray-zhang marked this pull request as draft April 1, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants