Skip to content

Conversation

@wilson-cl
Copy link
Collaborator

Ready EA Implementation for OPDATA-4790

Description

Adds a new xusd-usd-exchange-rate source adapter that fetches the round() value from the XUSD contract (0xE2Fc85BfB48C4cF147921fBE110cf92Ef9f26F94) on Ethereum mainnet via eth_call JSON-RPC. This adapter supports the XUSD-USD exchange rate feed for Stream.

Changes

  • Added new xusd-usd-exchange-rate source adapter with round endpoint
  • Implemented HTTP transport using direct eth_call JSON-RPC to query the on-chain round() function
  • Configured ETHEREUM_RPC_URL as a required environment variable (node operators provide their own RPC endpoint)
  • Added integration tests covering success, RPC errors, missing results, and server errors
  • Added unit tests for transport utility functions (buildEthCallRequest, parseHexToInt, buildErrorResponse, buildSuccessResponse)

Steps to Test

  1. Set the ETHEREUM_RPC_URL environment variable to a valid Ethereum mainnet RPC endpoint
  2. Build and start the adapter:
    yarn build
    yarn start
  3. Send a request to the round endpoint:
    curl -X POST http://localhost:8080 \
      -H "Content-Type: application/json" \
      -d '{"data": {"endpoint": "round"}}'
  4. Verify the response contains the current round value (integer)
  5. Run tests:
    yarn test packages/sources/xusd-usd-exchange-rate

Quality Assurance

  • 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.
  • 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.
  • If a new adapter was made, or a new endpoint was added, update the test-payload.json file with relevant requests.
  • The branch naming follows git flow (feature/x, chore/x, release/x, hotfix/x, fix/x) or is created from Jira.
  • This is related to a maximum of one Jira story or GitHub issue.
  • Types are safe (avoid TypeScript/TSLint features like any and disable, instead use more specific types).
  • 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

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 5005a98

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

This PR includes changesets to release 1 package
Name Type
@chainlink/xusd-usd-exchange-rate-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

@wilson-cl wilson-cl marked this pull request as draft December 10, 2025 07:46
@wilson-cl wilson-cl requested a review from Copilot December 10, 2025 07:52
Copy link
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

This PR introduces a new xusd-usd-exchange-rate source adapter that fetches the round value from the XUSD contract on Ethereum mainnet using JSON-RPC eth_call.

Key Changes:

  • Implements a new adapter with a round endpoint that queries the round() function from contract 0xE2Fc85BfB48C4cF147921fBE110cf92Ef9f26F94
  • Uses HTTP transport with direct eth_call JSON-RPC to retrieve on-chain data
  • Includes comprehensive unit and integration tests for transport functions and error handling scenarios

Reviewed changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/tsconfig.test.json Added reference to new adapter's test configuration
packages/tsconfig.json Added reference to new adapter's build configuration
packages/sources/xusd-usd-exchange-rate/tsconfig.test.json Test TypeScript configuration for the new adapter
packages/sources/xusd-usd-exchange-rate/tsconfig.json Build TypeScript configuration for the new adapter
packages/sources/xusd-usd-exchange-rate/test/unit/round.test.ts Unit tests for transport utility functions
packages/sources/xusd-usd-exchange-rate/test/integration/fixtures.ts Mock fixtures for integration tests
packages/sources/xusd-usd-exchange-rate/test/integration/adapter.test.ts Integration tests for adapter endpoints and error scenarios
packages/sources/xusd-usd-exchange-rate/test/integration/snapshots/adapter.test.ts.snap Jest snapshots for integration test assertions
packages/sources/xusd-usd-exchange-rate/test-payload.json Example test payload for the round endpoint
packages/sources/xusd-usd-exchange-rate/src/transport/round.ts HTTP transport implementation for eth_call RPC requests
packages/sources/xusd-usd-exchange-rate/src/index.ts Main adapter entry point and configuration
packages/sources/xusd-usd-exchange-rate/src/endpoint/round.ts Round endpoint definition and input parameters
packages/sources/xusd-usd-exchange-rate/src/endpoint/index.ts Endpoint exports
packages/sources/xusd-usd-exchange-rate/src/config/index.ts Adapter configuration including ETHEREUM_RPC_URL
packages/sources/xusd-usd-exchange-rate/package.json Package metadata and dependencies
Files not reviewed (1)
  • .pnp.cjs: Language not supported

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

@wilson-cl wilson-cl marked this pull request as ready for review December 10, 2025 07:53
@wilson-cl wilson-cl requested a review from Copilot December 10, 2025 08:31
Copy link
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

Copilot reviewed 17 out of 19 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • .pnp.cjs: Language not supported

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

@wilson-cl wilson-cl requested a review from Copilot December 10, 2025 13:43
Copy link
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

Copilot reviewed 17 out of 19 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • .pnp.cjs: Language not supported

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

Copy link
Contributor

@mxiao-cll mxiao-cll left a comment

Choose a reason for hiding this comment

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

What are we trying to do here? Just testing how the AI agent performs?

import { config } from '../config'
import { httpTransport } from '../transport/round'

export const inputParameters = new InputParameters({}, [{}])
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an EmptyInputParameters from framework

Comment on lines +4 to +5
export const XUSD_CONTRACT_ADDRESS = '0xE2Fc85BfB48C4cF147921fBE110cf92Ef9f26F94'
export const ROUND_FUNCTION_SELECTOR = '0x146ca531'
Copy link
Contributor

Choose a reason for hiding this comment

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

These should come from input

Comment on lines +88 to +93
prepareRequests: (params, config) => {
return params.map((param) => ({
params: [param],
request: buildEthCallRequest(config.ETHEREUM_RPC_URL),
}))
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong, you are building the same request over and over again. Just need to return 1 request here

},
'latest',
],
id: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we hardcoding this to 1 everytime?

@wilson-cl
Copy link
Collaborator Author

What are we trying to do here? Just testing how the AI agent performs?

yes

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.

2 participants