{"id":26233667,"url":"https://github.com/docknetwork/price-feed-adapter","last_synced_at":"2025-03-13T01:17:02.354Z","repository":{"id":53428592,"uuid":"342361407","full_name":"docknetwork/price-feed-adapter","owner":"docknetwork","description":"Chainlink external adapter for price feed of Dock token","archived":false,"fork":false,"pushed_at":"2024-02-22T21:45:32.000Z","size":427,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-02-22T22:38:51.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docknetwork.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-25T19:50:15.000Z","updated_at":"2024-02-22T21:45:35.000Z","dependencies_parsed_at":"2023-01-20T13:02:02.847Z","dependency_job_id":null,"html_url":"https://github.com/docknetwork/price-feed-adapter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docknetwork%2Fprice-feed-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docknetwork%2Fprice-feed-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docknetwork%2Fprice-feed-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docknetwork%2Fprice-feed-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docknetwork","download_url":"https://codeload.github.com/docknetwork/price-feed-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243318783,"owners_count":20272145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-13T01:17:01.636Z","updated_at":"2025-03-13T01:17:02.328Z","avatar_url":"https://github.com/docknetwork.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Price feed adapter\n\nFetches price from exchanges, takes median and writes them to chain. Currently supported price sources are Coinmarketcap, Coingecko, Cryptocompare and Binance. All the actions are written as small tasks.\n\nThis repo holds several components:\n\n- the adapter, which is the js module in [`./src`](./src), gets deployed to a chainlink node (by node operators) under the bridge name `dock_usd_bridge`\n- the [jobspecs](#Jobspecs), which define when the adapter function get scheduled to run\n- the server, which acts as a middleware for price data APIs (Coinmarketcap, Coingecko, etc.), and exposes:\n  - each price data API endpoint\n  - an endpoint that returns the median of all these APIs' prices\n\n## Deploying the adapter\n\nThe default adapter is the module in [`./src`](./src).\nThis is for chainlink node operators to deploy on their node.\n\nThis bridge should be deployed under the name `dock_usd_bridge`.\nThis can be checked in the admin dashboard of the oracle's chainlink node.\n\n### Customizing the adapter deployment\n\nAlternatively, node operators can tweak the deployment and jobspec in the following ways:\n\n#### To get price for DOCK/USD pair\n\n```js\nimport { execute } from './adapter';\nimport { coinmarketcap } from './endpoint';\nimport { coingecko } from './endpoint';\n\n// Get price from coinmarketcap\nconst data = await execute({ id: \"1\", data: {endpoint: coinmarketcap.NAME}} as AdapterRequest );\n\n// Get price from coingecko\nconst data = await execute({ id: \"1\", data: {endpoint: coingecko.NAME}} as AdapterRequest );\n\n// To get median price from multiple exchanges, the choice of exchanges is hardcoded in code\nimport { MEDIAN_PRICE } from './adapter';\nconst data = await execute({ id: \"1\", data: {endpoint: MEDIAN_PRICE}} as AdapterRequest );\n```\n\nThe `result` key of `data` will contain the price.\n\n#### To write price for DOCK/USD pair on chain\n\n```js\nimport { execute, WRITE_CMC_PRICE, WRITE_MEDIAN_PRICE } from './adapter';\n\n// To write coinmarketcap price\nconst data = await execute({ id: \"1\", data: {endpoint: WRITE_CMC_PRICE}} as AdapterRequest );\n\n// To write median price\nconst data = await execute({ id: \"1\", data: {endpoint: WRITE_MEDIAN_PRICE}} as AdapterRequest );\n\n// To write the price on chain when the current price has either deviated by 5% or is stale by 30 seconds\nconst data = await execute({ id: \"1\", data: {endpoint: WRITE_MEDIAN_PRICE, thresholdPct: 5, idleTime: 30}} as AdapterRequest );\n```\n\nThe `result` key of `data` will contain the block number.\n\n## HTTP server\n\nRunning the server. By default, runs at port 8080\n```\nts-node scripts/run-server.ts\n```\n\nEg. To fetch price at Binance, send GET request as\n```\ncurl -X POST -H \"Content-Type: application/json\" http://localhost:8080 --data '{\"id\":\"1\",\"data\": {\"endpoint\": \"Binance\"}}'\n```\n\nEg. To fetch median price of all sources, send GET request as\n```\ncurl -X POST -H \"Content-Type: application/json\" http://localhost:8080 --data '{\"id\":\"1\",\"data\": {\"endpoint\": \"median_price\"}}'\n```\n\nEg. To write median price of all sources on chain, send GET request as\n```\ncurl -X POST -H \"Content-Type: application/json\" http://localhost:8080 --data '{\"id\":\"1\",\"data\": {\"endpoint\": \"write_median_price\"}}'\n```\n## Jobspecs\n\nThere are 2 jobspecs. Each of them is initiated by a cron trigger each minute. They assume the adapter has been deployed with the bridge named `dock_usd_bridge`.  \n[Spec 1](price-feed-job-spec-1.json) will always write on the chain.  \n[Spec 2](price-feed-job-spec-2.json) will write on the chain when either the price deviates by 1% or 3600 seconds (1 hour) has passed.\n\n## Running the server\n\n```\nts-node scripts/run-server.ts\n```\n\n## Env variables\n\nThe following environment variables need to be set for the adapter to work.\n\n```\nCMC_API_KEY=\u003cCoinmarketcap API key\u003e\nMinimumAnswersForPriceFeed = \u003cMinimum answers (from different sources) required for price feed\u003e\nMinGasPrice = \u003cMinimum gas price\u003e\nMaxGas = \u003cMaximum allowed gas for a txn\u003e\nNODE_ENDPOINT=\u003cTCP endpoint of the blockchain node\u003e\nORACLE_SK=\u003cSecret key for Oracle's account\u003e\nORACLE_ADDRESS=\u003cEVM address of the Oracle\u003e\nPROXY_ADDRESS=\u003cEVM address of the proxy to price aggregator contract\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocknetwork%2Fprice-feed-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocknetwork%2Fprice-feed-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocknetwork%2Fprice-feed-adapter/lists"}