{"_id":"@chasevoorhees/osmonauts-math-decimal","_rev":"1-9843e3c334e65c8b4ec8fc2903d035a8","name":"@chasevoorhees/osmonauts-math-decimal","dist-tags":{"latest":"1.7.1"},"versions":{"1.7.0":{"name":"@chasevoorhees/osmonauts-math-decimal","version":"1.7.0","description":"Math calculations for Osmosis","author":{"name":"Dan Lynch","email":"pyramation@gmail.com"},"homepage":"https://github.com/osmosis-labs/osmojs/tree/master/packages/osmojs#readme","license":"SEE LICENSE IN LICENSE","main":"dist/index.js","module":"dist/index.mjs","typings":"dist/index.d.ts","directories":{"lib":"src","test":"__tests__"},"scripts":{"build:cjs":"yarn tsc -p tsconfig.json --outDir dist --module commonjs || true","build:mjs":"yarn tsc -p tsconfig.json --outDir mjs --module es2022 --declaration false || true","clean:mjs":"rimraf mjs","clean:dist":"rimraf dist","clean":"npm run clean:mjs && npm run clean:dist","build:rename":"publish-scripts --cmd rename --srcDir mjs --outDir dist --findExt js --replaceExt mjs --no-rmDir","build":"npm run clean && npm run build:cjs && npm run build:mjs && npm run build:rename","codegen":"cross-env NODE_ENV=development babel-node scripts/codegen.js","prepare":"npm run build","lint":"eslint .","format":"eslint . --fix","test":"jest","test:watch":"jest --watch","test:debug":"node --inspect node_modules/.bin/jest --runInBand"},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/chasevoorhees/osmojs-workspace-decimal.git"},"keywords":[],"bugs":{"url":"https://github.com/osmosis-labs/osmojs/issues"},"devDependencies":{"@babel/cli":"7.22.9","@babel/core":"7.22.9","@babel/eslint-parser":"^7.22.9","@babel/generator":"7.22.9","@babel/node":"^7.22.6","@babel/parser":"^7.22.7","@babel/plugin-proposal-class-properties":"7.18.6","@babel/plugin-proposal-export-default-from":"7.22.5","@babel/plugin-proposal-nullish-coalescing-operator":"7.18.6","@babel/plugin-proposal-numeric-separator":"7.18.6","@babel/plugin-proposal-object-rest-spread":"7.20.7","@babel/plugin-proposal-optional-chaining":"7.21.0","@babel/plugin-transform-runtime":"7.22.9","@babel/preset-env":"7.22.9","@babel/preset-typescript":"^7.22.5","@babel/traverse":"7.22.8","@babel/types":"7.22.5","@chain-registry/assets":"1.19.0","@types/jest":"^29.5.3","@types/jest-in-case":"^1.0.6","axios":"^0.27.2","babel-core":"7.0.0-bridge.0","babel-jest":"29.6.1","babel-watch":"^7.8.1","case":"1.6.3","chain-registry":"1.18.0","cross-env":"^7.0.2","eslint":"8.45.0","eslint-config-prettier":"^8.8.0","eslint-plugin-prettier":"^5.0.0","glob":"8.0.3","jest":"^29.6.1","jest-in-case":"^1.0.2","mkdirp":"1.0.4","prettier":">=2.7.0","publish-scripts":"0.1.0","rimraf":"3.0.2","ts-jest":"^29.1.1","typescript":"^5.0.4"},"dependencies":{"@chain-registry/types":"0.16.0","@chain-registry/utils":"1.13.1","bignumber.js":"9.1.1","decimal.js":"10.4.3","long":"5.2.3","osmojs":"^16.5.1"},"_id":"@chasevoorhees/osmonauts-math-decimal@1.7.0","gitHead":"d4a3defc14c09d66c9201511a42b655f0d6aad47","_nodeVersion":"18.16.1","_npmVersion":"9.8.0","dist":{"integrity":"sha512-ebALO15VmE8BMVobgDHcChRGWjxEyZn8FXq5c8Z2uMN0El+PGzs9kzmGH2bUuloaDFeyz1RjfXKl1ntFGT2D6w==","shasum":"17a542870d25ea5d203b36ee072047c7c7134839","tarball":"https://registry.npmjs.org/@chasevoorhees/osmonauts-math-decimal/-/osmonauts-math-decimal-1.7.0.tgz","fileCount":30,"unpackedSize":86118,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIANi1tYH9+2AtbLqVhq9ltJjdyhI2tiRoC5ZzWeq6ZFRAiEAmoposyAOPVVvDWgV7Aj5rQTLT7fKlDhsYGiffeRWmpM="}]},"_npmUser":{"name":"chasevoorhees","email":"chase@csvsoftware.com"},"maintainers":[{"name":"chasevoorhees","email":"chase@csvsoftware.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/osmonauts-math-decimal_1.7.0_1699424522728_0.45417604355691066"},"_hasShrinkwrap":false},"1.7.1":{"name":"@chasevoorhees/osmonauts-math-decimal","version":"1.7.1","description":"Math calculations for Osmosis","author":{"name":"Dan Lynch","email":"pyramation@gmail.com"},"homepage":"https://github.com/osmosis-labs/osmojs/tree/master/packages/osmojs#readme","license":"SEE LICENSE IN LICENSE","main":"dist/index.js","module":"dist/index.mjs","typings":"dist/index.d.ts","directories":{"lib":"src","test":"__tests__"},"scripts":{"build:cjs":"yarn tsc -p tsconfig.json --outDir dist --module commonjs || true","build:mjs":"yarn tsc -p tsconfig.json --outDir mjs --module es2022 --declaration false || true","clean:mjs":"rimraf mjs","clean:dist":"rimraf dist","clean":"npm run clean:mjs && npm run clean:dist","build:rename":"publish-scripts --cmd rename --srcDir mjs --outDir dist --findExt js --replaceExt mjs --no-rmDir","build":"npm run clean && npm run build:cjs && npm run build:mjs && npm run build:rename","codegen":"cross-env NODE_ENV=development babel-node scripts/codegen.js","prepare":"npm run build","lint":"eslint .","format":"eslint . --fix","test":"jest","test:watch":"jest --watch","test:debug":"node --inspect node_modules/.bin/jest --runInBand"},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/chasevoorhees/osmojs-workspace-decimal.git"},"keywords":[],"bugs":{"url":"https://github.com/osmosis-labs/osmojs/issues"},"devDependencies":{"@babel/cli":"7.22.9","@babel/core":"7.22.9","@babel/eslint-parser":"^7.22.9","@babel/generator":"7.22.9","@babel/node":"^7.22.6","@babel/parser":"^7.22.7","@babel/plugin-proposal-class-properties":"7.18.6","@babel/plugin-proposal-export-default-from":"7.22.5","@babel/plugin-proposal-nullish-coalescing-operator":"7.18.6","@babel/plugin-proposal-numeric-separator":"7.18.6","@babel/plugin-proposal-object-rest-spread":"7.20.7","@babel/plugin-proposal-optional-chaining":"7.21.0","@babel/plugin-transform-runtime":"7.22.9","@babel/preset-env":"7.22.9","@babel/preset-typescript":"^7.22.5","@babel/traverse":"7.22.8","@babel/types":"7.22.5","@chain-registry/assets":"1.19.0","@types/jest":"^29.5.3","@types/jest-in-case":"^1.0.6","axios":"^0.27.2","babel-core":"7.0.0-bridge.0","babel-jest":"29.6.1","babel-watch":"^7.8.1","case":"1.6.3","chain-registry":"1.18.0","cross-env":"^7.0.2","eslint":"8.45.0","eslint-config-prettier":"^8.8.0","eslint-plugin-prettier":"^5.0.0","glob":"8.0.3","jest":"^29.6.1","jest-in-case":"^1.0.2","mkdirp":"1.0.4","prettier":">=2.7.0","publish-scripts":"0.1.0","rimraf":"3.0.2","ts-jest":"^29.1.1","typescript":"^5.0.4"},"dependencies":{"@chain-registry/types":"0.16.0","@chain-registry/utils":"1.13.1","bignumber.js":"9.1.1","decimal.js":"10.4.3","long":"5.2.3","osmojs":"^16.5.1"},"_id":"@chasevoorhees/osmonauts-math-decimal@1.7.1","gitHead":"d4a3defc14c09d66c9201511a42b655f0d6aad47","_nodeVersion":"18.16.1","_npmVersion":"9.8.0","dist":{"integrity":"sha512-cAOG4r+Fk++81ixgH/c6SZTog51lrkJwBnGNhj1IhHhMyJjC6fflYEIKelJfrh8OyIObQjMIwDs+ayixUAWBPA==","shasum":"c5157b76c3ae0514b51c39dfb78ca3f1b551f14f","tarball":"https://registry.npmjs.org/@chasevoorhees/osmonauts-math-decimal/-/osmonauts-math-decimal-1.7.1.tgz","fileCount":30,"unpackedSize":87012,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCaLm8q7PwUIGtzHYwzzvbheBPGcyPvDqelrxGVRfPwRwIhAObx70n+GZU/Btrnt8a/MLj3LZRUpXWeV+Z6NAfBIsNQ"}]},"_npmUser":{"name":"chasevoorhees","email":"chase@csvsoftware.com"},"maintainers":[{"name":"chasevoorhees","email":"chase@csvsoftware.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/osmonauts-math-decimal_1.7.1_1699425826152_0.4364242755975196"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-08T06:22:02.617Z","1.7.0":"2023-11-08T06:22:02.926Z","modified":"2023-11-08T06:43:46.462Z","1.7.1":"2023-11-08T06:43:46.307Z"},"maintainers":[{"name":"chasevoorhees","email":"chase@csvsoftware.com"}],"description":"Math calculations for Osmosis","homepage":"https://github.com/osmosis-labs/osmojs/tree/master/packages/osmojs#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/chasevoorhees/osmojs-workspace-decimal.git"},"author":{"name":"Dan Lynch","email":"pyramation@gmail.com"},"bugs":{"url":"https://github.com/osmosis-labs/osmojs/issues"},"license":"SEE LICENSE IN LICENSE","readme":"# @osmonauts/math\n\n<p align=\"center\">\n  <a href=\"https://github.com/osmosis-labs/osmojs\">\n    <img width=\"150\" src=\"https://user-images.githubusercontent.com/545047/195456198-c35bf731-255e-42b6-833b-e76df553eec8.svg\">\n  </a>\n</p>\n\n<p align=\"center\" width=\"100%\">\n  <a href=\"https://github.com/osmosis-labs/osmojs/actions/workflows/run-tests.yaml\">\n    <img height=\"20\" src=\"https://github.com/osmosis-labs/osmojs/actions/workflows/run-tests.yaml/badge.svg\" />\n  </a>\n   <a href=\"https://github.com/osmosis-labs/osmojs/blob/main/LICENSE\"><img height=\"20\" src=\"https://img.shields.io/badge/license-MIT-blue.svg\"></a>\n   <a href=\"https://www.npmjs.com/package/osmojs\"><img height=\"20\" src=\"https://img.shields.io/github/package-json/v/osmosis-labs/osmojs?filename=packages%2Fosmojs%2Fpackage.json\"></a>\n</p>\n\n[OsmosJS](https://github.com/osmosis-labs/osmojs) makes it easy to compose and broadcast Osmosis and Cosmos messages, with all of the proto and amino encoding handled for you.\n\n---\n\n## install\n\n```sh\nnpm install @osmonauts/math\n```\n\n## Table of Contents\n\n- [@osmonauts/math](#osmonautsmath)\n  - [install](#install)\n  - [Table of Contents](#table-of-contents)\n  - [Calculations](#calculations)\n    - [Pool Calculations](#pool-calculations)\n      - [`calcPoolLiquidity`](#calcpoolliquidity)\n      - [`calcCoinsNeededForValue`](#calccoinsneededforvalue)\n      - [`calcMaxCoinsForPool`](#calcmaxcoinsforpool)\n      - [`calcShareOutAmount`](#calcshareoutamount)\n      - [`calcPoolAprs`](#calcpoolaprs)\n    - [Swap Calculations](#swap-calculations)\n      - [`getRoutesForTrade`](#getroutesfortrade)\n      - [`calcAmountWithSlippage`](#calcamountwithslippage)\n      - [`calcPriceImpactGivenIn`](#calcpriceimpactgivenin)\n      - [`calcPriceImpactGivenOut`](#calcpriceimpactgivenout)\n  - [Publishing](#publishing)\n  - [Credits](#credits)\n  - [Disclaimer](#disclaimer)\n\n## Calculations\n\n### Pool Calculations\n\n#### `calcPoolLiquidity`\n\nCalculate a pool's liquidity.\n\n```js\nimport { calcPoolLiquidity } from \"@osmonauts/math\";\n\nconst liquidity = calcPoolLiquidity(pool, prices);\n```\n\nPool liquidity is calculated using the formula below:\n$$liquidity=\\dfrac{tokenA}{10^{exponentA}}\\times priceA + \\dfrac{tokenB}{10^{exponentB}}\\times priceB$$\nFor pools with multiple tokens, just add more tokens to the end.\n\n#### `calcCoinsNeededForValue`\n\nCalculate the coins needed in a pool for the given dollar value.\n\n```js\nimport { calcCoinsNeededForValue } from \"@osmonauts/math\";\n\nconst coinsNeeded = calcCoinsNeededForValue(prices, poolInfo, value);\n```\n\nThe amount of either of the tokens needed in a pool is calculated using the formula below:\n\n$$amountNeeded=\\dfrac{tokenWeight}{totalWeight}\\times value \\div price\\times 10^{exponent}$$\n\n#### `calcMaxCoinsForPool`\n\nCalculate the maximum coins affordable in the balance for a given pool.\n\n```js\nimport { calcMaxCoinsForPool } from \"@osmonauts/math\";\n\nconst maxCoins = calcMaxCoinsForPool(prices, poolInfo, balances);\n```\n\n#### `calcShareOutAmount`\n\nOnce you have the coins needed from either `calcCoinsNeededForValue` or `calcMaxCoinsForPool`, you can use `calcShareOutAmount` to get the shareOutAmount for the pool:\n\n```js\nimport { calcShareOutAmount } from \"@osmonauts/math\";\n\nconst shareOutAmount = calcShareOutAmount(poolInfo, coinsNeeded);\n```\n\n#### `calcPoolAprs`\n\nCalculate a pool's APR which consists of three parts: superfluid APR, gauge APR and fees APR.\n\n```js\nimport { calcPoolAprs } from \"@osmonauts/math\";\n\nconst poolApr = calcPoolAprs({\n  activeGauges, // all the active gauges of a pool\n  pool, // pool info\n  prices, // priceHash\n  superfluidPools, // all the superfluid pools\n  aprSuperfluid, // apr of superfluid staking\n  lockupDurations, // all the lockup durations\n  volume7d, // 7 day trading volume of the pool\n  swapFee, // percentage value, e.g. 0.002\n  lockup = \"14\", // optional, specify the lockup duration\n  includeNonPerpetual = true, // optional, whether to include non-perpetual gauges\n})\n```\n\nFor superfluid APR, you can get all the pools' APRs from this [endpoint](https://api-osmosis.imperator.co/apr/v2/all).\n\nThe formula for calculating the gauge APR:\n\n$$gaugeAPR=\\dfrac{totalCoins-distributedCoins}{10^{exponent}}\\times price\\div liquidity\\times 36500$$\n\nFees APR works in a similar way:\n\n$$feesAPR=\\dfrac{tradingVolume7d}{7}\\times swapFee\\div liquidity\\times 36500$$\n\n### Swap Calculations\n\n#### `getRoutesForTrade`\n\nFind the available routes for trade given sell token and buy token, as well as pool pairs.\n\n```js\nimport { getRoutesForTrade, makePoolPairs } from \"@osmonauts/math\";\n\nconst pairs = makePoolPairs(pools, prices);\n\nconst routes = getRoutesForTrade({\n  trade: {\n    sell, // token to sell\n    buy, // token to buy\n  },\n  pairs,\n});\n```\n\n#### `calcAmountWithSlippage`\n\nCalculates the tokenOut amount after slippage, slippage is the number without the \"%\" part, e.g. if slippage is \"1%\", then pass in `1` as slippage, rather than `0.01`.\n\n```js\nimport { calcAmountWithSlippage } from \"@osmonauts/math\";\n\nconst tokenOutMinAmount = calcAmountWithSlippage(tokenOutAmount, slippage);\n```\n\n#### `calcPriceImpactGivenIn`\n\nCalculates price impact given the tokenIn info and the tokenOutDenom.\n\n```js\nimport { calcPriceImpactGivenIn } from \"@osmonauts/math\";\n\nconst priceImpact = calcPriceImpactGivenIn(\n  tokenIn, // tokenIn info\n  tokenOutDenom,\n  pool // the pool that contains both tokenIn and tokenOut as poolAssets\n);\n```\n\n#### `calcPriceImpactGivenOut`\n\nCalculates price impact given the tokenOut info and the tokenInDenom.\n\n```js\nimport { calcPriceImpactGivenOut } from \"@osmonauts/math\";\n\nconst priceImpact = calcPriceImpactGivenOut(\n  tokenOut, // tokenOut info\n  tokenInDenom,\n  pool // the pool that contains both tokenIn and tokenOut as poolAssets\n);\n```\n\n## Publishing\n\nBuild the types and then publish:\n\n```\nyarn build:ts\nyarn publish\n```\n\n## Credits\n\n🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.tech/validator)\n\nCode built with the help of these related projects:\n\n- [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) for generated CosmWasm contract Typescript classes\n- [@cosmology/telescope](https://github.com/cosmology-tech/telescope) a \"babel for the Cosmos\", Telescope is a TypeScript Transpiler for Cosmos Protobufs.\n- [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos ⚛️\n\n## Disclaimer\n\nAS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.\n\nNo developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.\n","readmeFilename":"README.md"}