Skip to content

Conversation

@chray-zhang
Copy link
Collaborator

@chray-zhang chray-zhang commented Dec 1, 2025

Closes OPDATA-4855

Description

Originally the solana-functions buffer-layout endpoint only supported MintLayout and SanctumPoolStateLayout. It did not support Token account programs. This change is to add support to deserialize and support Token Accounts

Changes

Implemented: https://solana-labs.github.io/solana-program-library/token/js/variables/AccountLayout.html

Steps to Test

Token Account:

chrayzhang@MB-C3H04RT9WT ~ % curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "endpoint": "buffer-layout",
      "field": "amount",
      "stateAccountAddress": "FvkbfMm98jefJWrqkvXvsSZ9RFaRBae8k6c1jaYA5vY3"
    }
  }' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   497  100   336  100   161    271    130  0:00:01  0:00:01 --:--:--   401
{
  "data": {
    "result": "34228815152"
  },
  "statusCode": 200,
  "result": "34228815152",
  "timestamps": {
    "providerDataRequestedUnixMs": 1764628385812,
    "providerDataReceivedUnixMs": 1764628386096
  },
  "meta": {
    "adapterName": "SOLANA_FUNCTIONS",
    "metrics": {
      "feedId": "{\"stateAccountAddress\":\"fvkbfmm98jefjwrqkvxvssz9rfarbae8k6c1jaya5vy3\",\"field\":\"amount\"}"
    }
  }
}

Mint account:

chrayzhang@MB-C3H04RT9WT ~ % curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "endpoint": "buffer-layout",
      "field": "supply",
      "stateAccountAddress": "3b8X44fLF9ooXaUm3hhSgjpmVs6rZZ3pPoGnGahc3Uu7"
    }
  }' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   497  100   336  100   161   1635    783 --:--:-- --:--:-- --:--:--  2424
{
  "data": {
    "result": "34156329357"
  },
  "statusCode": 200,
  "result": "34156329357",
  "timestamps": {
    "providerDataRequestedUnixMs": 1764628429970,
    "providerDataReceivedUnixMs": 1764628430044
  },
  "meta": {
    "adapterName": "SOLANA_FUNCTIONS",
    "metrics": {
      "feedId": "{\"stateAccountAddress\":\"3b8x44flf9ooxaum3hhsgjpmvs6rzz3ppogngahc3uu7\",\"field\":\"supply\"}"
    }
  }
}

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

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: e9a5a9f

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

This PR includes changesets to release 1 package
Name Type
@chainlink/solana-functions-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 changed the title Added TokenAccount Support [OPDATA-4855] Added TokenAccount Support for solana-functions Dec 1, 2025
@chray-zhang chray-zhang requested a review from dskloetc December 1, 2025 23:00
@chray-zhang chray-zhang marked this pull request as ready for review December 1, 2025 23:01
@chray-zhang chray-zhang enabled auto-merge (squash) December 2, 2025 05:43
// https://github.com/solana-labs/solana-program-library/blob/token-v4.0.0/token/program/src/state.rs#L37
const MINT_SIZE = 82
// https://github.com/solana-labs/solana-program-library/blob/token-v4.0.0/token/program/src/state.rs#L129
const TOKEN_ACCOUNT_SIZE = 165
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR is not necessary because you can get the data you want using the extension endpoint as I described here: https://chainlink-core.slack.com/archives/C09N0DEH6M8/p1764661162177669?thread_ts=1764082643.124029&cid=C09N0DEH6M8

But if you want to extend the buffer-layout endpoint to support AccountLayout, let's check the layout.span instead of hard coding the lengths.
We can just provide an array of layouts for each program address in the map and loop to find the one with the correct length.

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