{"_id":"@duality-labs/duality-front-end-sdk","_rev":"7-1952932057e9e2105461144935d41819","name":"@duality-labs/duality-front-end-sdk","dist-tags":{"latest":"0.1.4"},"versions":{"0.1.0":{"name":"@duality-labs/duality-front-end-sdk","version":"0.1.0","description":"Component hooks and tools to interact with the Duality Dex chain and indexer for front ends","author":{"name":"hello@duality.xyz"},"homepage":"https://github.com/duality-labs/duality-front-end-sdk#readme","license":"MIT","main":"dist/main/index.js","module":"dist/module/index.js","types":"dist/types/index.d.ts","scripts":{"build:main:dir":"esbuild src/**/*.ts --format=esm --outdir=dist/main","build:main:bundle":"esbuild --bundle src/index.ts --format=cjs --outfile=dist/main/bundle.js","build:main":"npm run build:main:dir && npm run build:main:bundle","build:module:dir":"esbuild src/**/*.ts --format=esm --outdir=dist/module","build:module:bundle":"esbuild --bundle src/index.ts --format=esm --outfile=dist/module/bundle.js","build:module":"npm run build:module:dir && npm run build:module:bundle","build:types":"tsc --emitDeclarationOnly --outDir dist/types","build":"npm run clean && npm run build:main && npm run build:module && npm run build:types","clean":"rimraf dist","prepublishOnly":"npm run build"},"dependencies":{"swr":"^2.2.4","react":"^18.2.0"},"devDependencies":{"esbuild":"^0.19.11","rimraf":"^5.0.5","typescript":"^5.3.3"},"optionalDependencies":{"react":"^18.2.0"},"repository":{"type":"git","url":"git+https://github.com/duality-labs/duality-front-end-sdk.git"},"bugs":{"url":"https://github.com/duality-labs/duality-front-end-sdk/issues"},"gitHead":"7e270e6178b31768068c1a83320837dc1b4fcbf7","_id":"@duality-labs/duality-front-end-sdk@0.1.0","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-Av+mw1goiUnw7qIU2MSkj/uYOKVJLyTC1Wv0rQL0aGS/bMlHXz+S8sT+14vezVaxlFuQQvH3UpGPbGLDZzXoAA==","shasum":"ec6f7b6bb3e60cbf072e20acc5e3df4bdd0acdb1","tarball":"https://registry.npmjs.org/@duality-labs/duality-front-end-sdk/-/duality-front-end-sdk-0.1.0.tgz","fileCount":17,"unpackedSize":284057,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsDE7EDoWrqYauJ77z5PQZ0s03B9wqH9Gc26mzGuBazwIhAPIwPfRskNzl3JHOgiQ785JZWkUBQQIegWyCKJKJ904n"}]},"_npmUser":{"name":"duality-labs-david","email":"david@duality.xyz"},"directories":{},"maintainers":[{"name":"duality-labs-david","email":"david@duality.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/duality-front-end-sdk_0.1.0_1704523636983_0.10757163916276768"},"_hasShrinkwrap":false},"0.1.2":{"name":"@duality-labs/duality-front-end-sdk","version":"0.1.2","description":"Component hooks and tools to interact with the Duality Dex chain and indexer for front ends","author":{"name":"hello@duality.xyz"},"homepage":"https://github.com/duality-labs/duality-front-end-sdk#readme","license":"MIT","main":"dist/main/index.js","module":"dist/module/index.js","types":"dist/types/index.d.ts","scripts":{"build:main:dir":"esbuild src/**/*.ts --format=cjs --outdir=dist/main","build:main:bundle":"esbuild --bundle src/index.ts --format=cjs --outfile=dist/main/bundle.js","build:main":"npm run build:main:dir && npm run build:main:bundle","build:module:dir":"esbuild src/**/*.ts --format=esm --outdir=dist/module","build:module:bundle":"esbuild --bundle src/index.ts --format=esm --outfile=dist/module/bundle.js","build:module":"npm run build:module:dir && npm run build:module:bundle","build:types":"tsc --emitDeclarationOnly --outDir dist/types","build":"npm run clean && npm run build:main && npm run build:module && npm run build:types","clean":"rimraf dist","prepublishOnly":"npm run build"},"dependencies":{"swr":"^2.2.4","react":"^18.2.0"},"devDependencies":{"@cosmjs/stargate":"0.31.1","esbuild":"^0.19.11","rimraf":"^5.0.5","typescript":"^5.3.3"},"optionalDependencies":{"react":"^18.2.0"},"repository":{"type":"git","url":"git+https://github.com/duality-labs/duality-front-end-sdk.git"},"bugs":{"url":"https://github.com/duality-labs/duality-front-end-sdk/issues"},"gitHead":"7f88531bae8a50543ead40128ccb0c514b92609e","_id":"@duality-labs/duality-front-end-sdk@0.1.2","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-FoCdRGRl+l7OTiCG/JqgM+wAI/Mr1src9NNIg3GurJYkRseTgD4jXEtZgryEo6Kci2WEOqaeNYZlB+Vjn8jnlw==","shasum":"1cc39429b837875ebfb0341820fa8c8f29b7cc06","tarball":"https://registry.npmjs.org/@duality-labs/duality-front-end-sdk/-/duality-front-end-sdk-0.1.2.tgz","fileCount":26,"unpackedSize":302243,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDUG5hgz+D27VLEhB+1csXNsNwx1gKcD0FejW/0f5851wIgKOFvpDQK1webZAOPu3Cr8NPaqBazdyFoRboQpl/19og="}]},"_npmUser":{"name":"duality-labs-david","email":"david@duality.xyz"},"directories":{},"maintainers":[{"name":"duality-labs-david","email":"david@duality.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/duality-front-end-sdk_0.1.2_1704667737116_0.7534264996261149"},"_hasShrinkwrap":false},"0.1.3":{"name":"@duality-labs/duality-front-end-sdk","version":"0.1.3","description":"Component hooks and tools to interact with the Duality Dex chain and indexer for front ends","author":{"name":"hello@duality.xyz"},"homepage":"https://github.com/duality-labs/duality-front-end-sdk#readme","license":"MIT","main":"dist/main/index.js","module":"dist/module/index.js","types":"dist/types/index.d.ts","scripts":{"build:main:dir":"esbuild src/*.ts src/**/*.ts --format=cjs --outdir=dist/main","build:main:bundle":"esbuild --bundle src/index.ts --format=cjs --minify --sourcemap --outfile=dist/main/bundle.js","build:main":"npm run build:main:dir && npm run build:main:bundle","build:module:dir":"esbuild src/*.ts src/**/*.ts --format=esm --outdir=dist/module","build:module:bundle":"esbuild --bundle src/index.ts --format=esm --minify --sourcemap --outfile=dist/module/bundle.js","build:module":"npm run build:module:dir && npm run build:module:bundle","build:types":"tsc --emitDeclarationOnly --outDir dist/types","build":"npm run clean && npm run build:main && npm run build:module && npm run build:types","clean":"rimraf dist","prepublishOnly":"npm run build"},"dependencies":{"swr":"^2.2.4","react":"^18.2.0"},"devDependencies":{"@cosmjs/stargate":"0.31.1","esbuild":"^0.19.11","rimraf":"^5.0.5","typescript":"^5.3.3"},"optionalDependencies":{"react":"^18.2.0"},"repository":{"type":"git","url":"git+https://github.com/duality-labs/duality-front-end-sdk.git"},"bugs":{"url":"https://github.com/duality-labs/duality-front-end-sdk/issues"},"gitHead":"cb5317f298d255e02825b8564d3ac7d23e005925","_id":"@duality-labs/duality-front-end-sdk@0.1.3","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-zQZguVKV+8kujM/TZx/tC+cxsGwhtm2LKbfyDz4nCtYi7QoBRFuT0mhLiC51696EPkkJvFSbSn100xTkcCGsQw==","shasum":"aff5b679b878650ab1ffd317bacb933ecccef886","tarball":"https://registry.npmjs.org/@duality-labs/duality-front-end-sdk/-/duality-front-end-sdk-0.1.3.tgz","fileCount":30,"unpackedSize":349599,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGru2fDzo8ZOy9w7j7Un+V0aa+UQuW7U9NcNYE0/qChSAiAkn779zcbE3tcaSlh4SuhyXTCQo/KGFz8cxSnxpotgfA=="}]},"_npmUser":{"name":"duality-labs-david","email":"david@duality.xyz"},"directories":{},"maintainers":[{"name":"duality-labs-david","email":"david@duality.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/duality-front-end-sdk_0.1.3_1704668284272_0.8365841166069528"},"_hasShrinkwrap":false},"0.1.4":{"name":"@duality-labs/duality-front-end-sdk","version":"0.1.4","description":"Component hooks and tools to interact with the Duality Dex chain and indexer for front ends","author":{"name":"hello@duality.xyz"},"homepage":"https://github.com/duality-labs/duality-front-end-sdk#readme","license":"MIT","main":"dist/main/index.js","module":"dist/module/index.js","types":"dist/types/index.d.ts","scripts":{"build:main:dir":"esbuild src/*.ts src/**/*.ts --format=cjs --outdir=dist/main","build:main:bundle":"esbuild --bundle src/index.ts --format=cjs --minify --sourcemap --outfile=dist/main/bundle.js","build:main":"npm run build:main:dir && npm run build:main:bundle","build:module:dir":"esbuild src/*.ts src/**/*.ts --format=esm --outdir=dist/module","build:module:bundle":"esbuild --bundle src/index.ts --format=esm --minify --sourcemap --outfile=dist/module/bundle.js","build:module":"npm run build:module:dir && npm run build:module:bundle","build:types":"tsc --emitDeclarationOnly --outDir dist/types","build":"npm run clean && npm run build:main && npm run build:module && npm run build:types","clean":"rimraf dist","prepublishOnly":"npm run build"},"dependencies":{"swr":"^2.2.4","react":"^18.2.0"},"devDependencies":{"@cosmjs/stargate":"0.31.1","esbuild":"^0.19.11","react-hot-toast":"^2.4.1","rimraf":"^5.0.5","typescript":"^5.3.3"},"optionalDependencies":{"react":"^18.2.0"},"repository":{"type":"git","url":"git+https://github.com/duality-labs/duality-front-end-sdk.git"},"bugs":{"url":"https://github.com/duality-labs/duality-front-end-sdk/issues"},"gitHead":"8ed599ed8da7cca2767a7d2cbfaf5215eab57d71","_id":"@duality-labs/duality-front-end-sdk@0.1.4","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-uLKlWI1vRwVgwCdehC7/VhUe6vsBxIRYTpmddrmprcMtAASNiprgS/uv0vHzHBDn7g/9lMp5uhT6cFvXoICRfQ==","shasum":"46da67412c3d9f45881815a3652210161dae4fcb","tarball":"https://registry.npmjs.org/@duality-labs/duality-front-end-sdk/-/duality-front-end-sdk-0.1.4.tgz","fileCount":30,"unpackedSize":349865,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBFHZJreizP8No18+nzYab8zRccf/YYL9YuFlIEqijckAiArZx4YWyedRvlKSno35Z75pOTvN+sqLYlGMUUgRzvCNw=="}]},"_npmUser":{"name":"duality-labs-david","email":"david@duality.xyz"},"directories":{},"maintainers":[{"name":"duality-labs-david","email":"david@duality.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/duality-front-end-sdk_0.1.4_1704669634246_0.6286298404592798"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-06T06:47:16.851Z","0.1.0":"2024-01-06T06:47:17.174Z","modified":"2024-01-07T23:20:34.610Z","0.1.1":"2024-01-07T22:16:42.504Z","0.2.0":"2024-01-07T22:31:26.039Z","0.1.2":"2024-01-07T22:48:57.272Z","0.1.3":"2024-01-07T22:58:04.618Z","0.1.4":"2024-01-07T23:20:34.425Z"},"maintainers":[{"name":"duality-labs-david","email":"david@duality.xyz"}],"description":"Component hooks and tools to interact with the Duality Dex chain and indexer for front ends","homepage":"https://github.com/duality-labs/duality-front-end-sdk#readme","repository":{"type":"git","url":"git+https://github.com/duality-labs/duality-front-end-sdk.git"},"author":{"name":"hello@duality.xyz"},"bugs":{"url":"https://github.com/duality-labs/duality-front-end-sdk/issues"},"license":"MIT","readme":"# Duality Front End SDK\n\nA collection of useful component hooks and tools to interact with the Duality\nDex chain and indexer for front ends.\n\n## Get Started\n\n`npm install @duality-labs/duality-front-end-sdk`\n\n## Using indexer data\n\nSee also:\n- https://github.com/duality-labs/hapi-indexer\n- https://hadron.notion.site/Indexer-API-a2eabb732292453196332cb2727e53f7\n\nSubscribing to indexer data updates may seem complicated at first, given that\nthe event stream returns partial updates and these updates need to be\naccumulated into a usable data state. The exposed classes here should help:\n\n- `IndexerStream<DataRow>`\n- `IndexerStreamAccumulateSingleDataSet<DataRow, DataSet>`\n- `IndexerStreamAccumulateDualDataSet<DataRow, DataSet>`\n- where `DataRow` is a TypeScript interface of an endpoint's row data shape\n- where `DataSet` is a Map type defining data accumulation from rows into a map\n\nA set of abstracted functions for higher level usage includes functions that\nmimic `fetch` behavior, awaiting for all requested data before resolving:\n\n- `fetchSingleDataSetFromIndexer<DataRow>`\n- `fetchDualDataSetFromIndexer<DataRow>`\n\nAnd React hook implementations to track a cumulative data state with each update\n- `useIndexerStreamOfSingleDataSet<DataRow>`\n- `useIndexerStreamOfDualDataSet<DataRow>`\n\n\n### Indexer usage Examples\n\nThis allows an abstraction of examples such as the following\n\nA simple fetch replacement, including [abortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) option:\n\n```ts\nimport { fetchSingleDataSetFromIndexer } from '@duality-labs/duality-front-end-sdk';\n\ntype TimeSeriesRow = [unixTime: number, values: number[]];\ntype TimeSeriesDataSet = Map<TimeSeriesRow['0'], TimeSeriesRow['1']>\n\nasync function getSortedTimeseries(url: string): Promise<TimeSeriesRow[]> {\n  const data: TimeSeriesDataSet =\n    await fetchSingleDataSetFromIndexer<TimeSeriesRow>(url);\n  return Array.from(data)\n    // sort by index (chronological timestamp)\n    .sort(([a], [b]) => a - b);\n}\n\n```\n\nor using an AbortController in a bad practice React useEffect fetch (demonstrating cleanup)\n\n```ts\nimport { fetchSingleDataSetFromIndexer } from '@duality-labs/duality-front-end-sdk';\n\nuseEffect(() => {\n  const abortController = new AbortController();\n  fetchSingleDataSetFromIndexer<TimeSeriesRow>(url, { abortController })\n    .then((data: TimeSeriesDataSet): TimeSeriesRow[] => {\n      return (\n        Array.from(data)\n          // sort by index (chronological timestamp)\n          .sort(([a], [b]) => a - b)\n      );\n    })\n    .then(setData);\n  // cleanup by aborting the fetch\n  return () => abortController.abort();\n}, [url]);\n```\n\nSubscribing to updates using base data accumulation Class:\n\n```ts\nimport { IndexerStreamAccumulateSingleDataSet } from '@duality-labs/duality-front-end-sdk';\n\n// to pass update data to a higher-level `onRealtimeCallback` function\nnew IndexerStreamAccumulateSingleDataSet<TimeSeriesRow>(url, {\n  onUpdate: (dataUpdates) => {\n    // note: TradingView data needs to be in chronological order\n    // and our indexer API delivers results in reverse-chronological order\n    const chronologicalUpdates = dataUpdates.reverse();\n    for (const row of chronologicalUpdates) {\n      // translate indexer API data row into TradingView candle object\n      onRealtimeCallback(getBarFromTimeSeriesRow(row));\n    }\n  },\n});\n```\n\nSubscribing to updates using data accumulation React Hooks:\n\n```ts\nimport { useMemo } from 'react';\nimport { useIndexerStreamOfSingleDataSet } from '@duality-labs/duality-front-end-sdk';\n\nexport type TokenPairReserves = [\n  token0: string,\n  token1: string,\n  reserve0: number,\n  reserve1: number\n];\ntype DataRow = [index: number, values: TokenPairReserves];\n\ntype TokenPairsState = {\n  data: TokenPairReserves[] | undefined;\n  error: Error | null;\n};\n\nexport default function useTokenPairs(): TokenPairsState {\n  const { data, error } =\n    useIndexerStreamOfSingleDataSet<DataRow>(`${indexerAPI}/liquidity/pairs`);\n\n  const values: TokenPairReserves[] | undefined = useMemo(() => {\n    if (data) {\n      const values = Array.from(data)\n        .sort(([a], [b]) => a - b)\n        .map((row) => row[1]);\n      return values;\n    }\n  }, [data]);\n\n  // return state\n  return { data: values, error: error || null };\n}\n```\n\nSubscribing to updates of a multiple dataset endpoint with React Hooks\n\n```ts\nimport { useIndexerStreamOfDualDataSet } from '@duality-labs/duality-front-end-sdk';\n\ntype ReserveDataRow = [tickIndex: number, reserves: number];\ntype ReserveDataSet = Map<ReserveDataRow['0'], ReserveDataRow['1']>;\n\n// add convenience method to fetch liquidity maps of a pair\nexport function useTokenPairMapLiquidity([tokenIdA, tokenIdB]: [string?, string? ]): {\n  // note that two data sets are returned by useIndexerStreamOfDualDataSet\n  data?: [ReserveDataSet, ReserveDataSet];\n  error?: unknown;\n} {\n  // stream data from indexer\n  return useIndexerStreamOfDualDataSet<ReserveDataRow>(\n    tokenIdA && tokenIdB && `${indexerAPI}/liquidity/pair/${tokenIdA}/${tokenIdB}`,\n    {\n      // remove entries of value 0 from the accumulated map, they are not used\n      mapEntryRemovalValue: 0,\n    }\n  );\n}\n```\n","readmeFilename":"README.md"}