Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dskloetc
Copy link
Contributor

@dskloetc dskloetc commented Sep 19, 2025

https://smartcontract-it.atlassian.net/browse/OPDATA-3674

Description

We need total balance for a list of Avalanche addresses for a proof-of-reserves feed.
Some of these addresses are P-chain addresses.
The avalanche-platform EA already interacts with Avalanche P-chain, although it currently doesn't appear to be used by anything.

Unfortunately its existing balance endpoint only returns the stake of the requested addresses.

This PR adds a new totalBalance endpoint which returns the sum of locked and unlocked balances and stake.

Balances are for a specific asset, which defaults to the asset ID of the native AVA token, but can be set to something else as well.

Changes

  1. Add new endpoint and transport for totalBalance.
  2. Make 2 requests per address for balances and stake.
  3. Use grouped runner to limit simultaneous requests.

Steps to Test

  1. Unit tests and integration tests added.
  2. Tested manually with proof-of-reserves in another branch with other necessary changes in por-address-list.
curl --silent -S -X POST "$PROOF_OF_RESERVES_ADAPTER_URL" -H 'Content-Type: application/json' -d '{
  "data": {
  "endpoint": "multiReserves",
  "input": [
    {
      "protocol": "por_address_list",
      "protocolEndpoint": "virtune",
      "pattern": "^(?!P-)",
      "accountId": "VIRAVAX",
      "network": "avalanche",
      "chainId": "43114",
      "indexer": "eth_balance"
    },
    {
      "protocol": "por_address_list",
      "protocolEndpoint": "virtune",
      "pattern": "^P-",
      "accountId": "VIRAVAX",
      "network": "avalanche",
      "chainId": "43114",
      "indexer": "avalanche_platform",
      "indexerEndpoint": "totalBalance"
    }
  ]
}
}'
{
  "jobRunID": "1",
  "result": "141310543515847143410000",
  "statusCode": 200,
  "data": {
    "result": "141310543515847143410000",
    "details": "{\"result\":\"55629103628758143410000\"},{\"result\":\"85681439887089000000000\"}",
    "statusCode": 200,
    "decimals": 18,
    "timestamps": {
      "providerDataRequestedUnixMs": 1758299425125,
      "providerDataReceivedUnixMs": 1758299427398
    }
  },
  "meta": {
    "adapterName": "PROOF_OF_RESERVES"
  },
  "metricsMeta": {
    "feedId": "63d2efe3aa16b75a6e1e35401f74056e"
  }
}

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 or update the soak testing blacklist.
  • 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.

Copy link

changeset-bot bot commented Sep 19, 2025

🦋 Changeset detected

Latest commit: 418f22d

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

This PR includes changesets to release 3 packages
Name Type
@chainlink/avalanche-platform-adapter Minor
@chainlink/proof-of-reserves-adapter Patch
@chainlink/renvm-address-set-adapter Patch

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

@dskloetc dskloetc marked this pull request as ready for review September 19, 2025 16:45
@dskloetc dskloetc requested a review from a team September 19, 2025 16:45
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.

I feel like this might be close enough to balance that we can just add a new parameter to?

Comment on lines 159 to 171
getBalance(address: string): Promise<GetBalanceResult> {
return this.callPlatformMethod({
method: 'getBalance',
address,
})
}

async getStake(address: string): Promise<GetStakeResult> {
return this.callPlatformMethod({
method: 'getStake',
address,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel we need these two

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean like this?
I'm not convinced this is an improvement.
It's the same number of lines of code but now in a single longer function.

@dskloetc
Copy link
Contributor Author

I feel like this might be close enough to balance that we can just add a new parameter to?

I think we can probably just delete the existing endpoint. Right now I'd rather not introduce unnecessary complexity for something that's not used.

@dskloetc dskloetc requested a review from mxiao-cll September 22, 2025 07:19
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