Computes the result of swapping some amount in, or amount out, given the parameters of the swapThe fee, plus the amount in, will never exceed the amount remaining if the swap’s amountSpecified is positive
The price after swapping the amount in/out, not to exceed the price target
amountIn
uint256
The amount to be swapped in, of either token0 or token1, based on the direction of the swap
amountOut
uint256
The amount to be received, of either token0 or token1, based on the direction of the swap
feeAmount
uint256
The amount of input that will be taken as a fee
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Ramses Technical Documentation","colors":{"primary":"#161718","light":"#FFFFFF","dark":"#FFFFFF"},"logo":{"light":"https://mintcdn.com/ramses/nvKKukknXVTxMy0x/images/logo.png?fit=max\u0026auto=format\u0026n=nvKKukknXVTxMy0x\u0026q=85\u0026s=8baedca01f01eb1da8b939c567f92483","dark":"https://mintcdn.com/ramses/nvKKukknXVTxMy0x/images/logo.png?fit=max\u0026auto=format\u0026n=nvKKukknXVTxMy0x\u0026q=85\u0026s=8baedca01f01eb1da8b939c567f92483"},"favicon":"https://mintcdn.com/ramses/nvKKukknXVTxMy0x/images/favicon.ico?fit=max\u0026auto=format\u0026n=nvKKukknXVTxMy0x\u0026q=85\u0026s=761eeae2d0e72c0f4a9f1f3f8257295e","api":{"playground":{}},"background":{"color":{"light":"#FFFFFF","dark":"#161718"}},"navbar":{"links":[{"href":"https://github.com/RamsesExchange","label":"GitHub"},{"href":"https://discord.com/ramses","label":"Discord"}],"primary":{"type":"github","href":"https://github.com/RamsesExchange/ramses-v3-contracts"}},"fonts":{"heading":{"family":"Inter","weight":600},"body":{"family":"Inter","weight":400}},"icons":{"library":"lucide"},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"ramses","hasAudioNarration":false,"actualSubdomain":"ramses","customDomains":["tech.ramses.xyz"],"gitSource":{"type":"github","owner":"ramsesexchange","repo":"technical-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a923e876fb84ee479df28a7","collectionId":"e79b79bf-9b2e-4d8a-86ae-1e6a32dd9f56","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6a923e876fb84ee479df28a7"},"entitlements":{},"buildId":"6a923e876fb84ee479df28a7","clientVersion":"0.0.3964","searchFilterCounts":[{"language":"default","tag":"Contracts","count":104},{"language":"default","tag":"Reference","count":89},{"language":"default","tag":"SDKs","count":18},{"language":"default","tag":"Periphery Interfaces","count":17},{"language":"default","tag":"Concepts","count":14},{"language":"default","tag":"Guides","count":14},{"language":"default","tag":"Core Libraries","count":14},{"language":"default","tag":"Core Interfaces","count":13},{"language":"default","tag":"Periphery Libraries","count":12},{"language":"default","tag":"Periphery Base","count":9}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-v7-file-tree","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-nav-generations","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"isAtlas":false,"googleFontsInlined":false},"customCss":[{"filePath":"custom.css","content":":root{--font-size-base:0.9375rem;--line-height-base:1.65}h1{font-size:1.75rem!important;letter-spacing:-.02em}h1,h2,h3,h4{font-weight:600!important}h2{font-size:1.35rem!important;letter-spacing:-.01em}h3,h4{font-size:1.1rem!important}h4{font-size:.95rem!important}li,p,td,th{font-size:var(--font-size-base);line-height:var(--line-height-base)}code:not(pre code){font-size:.85em}pre code{font-size:.8125rem;line-height:1.6}"}],"page":{"pagePath":"contracts/reference/core/libraries/SwapMath","slug":"/contracts/reference/core/libraries/SwapMath","pageMetadata":{"title":null,"description":null,"href":"/contracts/reference/core/libraries/SwapMath"},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,p:`p`,pre:`pre`,span:`span`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick.`}),`\n`,_jsx(Heading,{level:`2`,id:`functions`,children:`Functions`}),`\n`,_jsx(Heading,{level:`3`,id:`computeswapstep`,children:`computeSwapStep`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`solidity`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`solidity`,children:_jsxs(_components.code,{language:`solidity`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` computeSwapStep`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` uint160`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` sqrtRatioCurrentX96`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` uint160`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` sqrtRatioTargetX96`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` uint128`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` liquidity`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` int256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` amountRemaining`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` uint24`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` feePips`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`internal`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` pure`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` returns`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint160`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` sqrtRatioNextX96`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` amountIn`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` amountOut`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` feeAmount`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Computes the result of swapping some amount in, or amount out, given the parameters of the swap`}),`\n`,_jsxs(_components.p,{children:[`The fee, plus the amount in, will never exceed the amount remaining if the swap’s `,_jsx(_components.code,{children:`amountSpecified`}),` is positive`]}),`\n`,_jsx(Heading,{level:`4`,id:`parameters`,children:`Parameters:`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{style:{textAlign:`left`},children:`Name`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Type`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`sqrtRatioCurrentX96`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint160`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The current sqrt price of the pool`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`sqrtRatioTargetX96`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint160`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The price that cannot be exceeded, from which the direction of the swap is inferred`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`liquidity`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint128`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The usable liquidity`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`amountRemaining`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`int256`}),_jsx(_components.td,{style:{textAlign:`left`},children:`How much input or output amount is remaining to be swapped in/out`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`feePips`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint24`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The fee taken from the input amount, expressed in hundredths of a bip`})]})]})]}),`\n`,_jsx(Heading,{level:`4`,id:`return-values`,children:`Return Values:`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{style:{textAlign:`left`},children:`Name`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Type`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`sqrtRatioNextX96`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint160`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The price after swapping the amount in/out, not to exceed the price target`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`amountIn`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint256`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The amount to be swapped in, of either token0 or token1, based on the direction of the swap`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`amountOut`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint256`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The amount to be received, of either token0 or token1, based on the direction of the swap`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`feeAmount`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`uint256`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The amount of input that will be taken as a fee`})]})]})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":null,"description":null,"href":"/contracts/reference/core/libraries/SwapMath"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Functions","slug":"functions","depth":2,"children":[{"title":"computeSwapStep","slug":"computeswapstep","depth":3,"children":[]},{"title":"Parameters:","slug":"parameters","depth":4,"children":[]},{"title":"Return Values:","slug":"return-values","depth":4,"children":[]}]}],"codeExamples":{}},"jsLinks":[],"subdomain":"ramses","siteName":"Ramses Technical Documentation","title":"SwapMath - Ramses Technical Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-16T19:46:43.575Z","originalFileLocation":"contracts/reference/core/libraries/SwapMath.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"application-name\" content=\"Ramses Technical Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"SwapMath - Ramses Technical Documentation\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Ramses Technical Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://ramses.mintlify.app/_mintlify/api/og/v2?division=Core+Libraries\u0026amp;title=SwapMath\u0026amp;theme=7887b6fe79c9a8d82726952d\u0026amp;signature=d42fbaa680a955103d9ba83a3bf5a38e336d72d527b9a916ad3c8ce79b955ea2\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"SwapMath - Ramses Technical Documentation\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://ramses.mintlify.app/_mintlify/api/og/v2?division=Core+Libraries\u0026amp;title=SwapMath\u0026amp;theme=7887b6fe79c9a8d82726952d\u0026amp;signature=d42fbaa680a955103d9ba83a3bf5a38e336d72d527b9a916ad3c8ce79b955ea2\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/ramses/3PsiHICiYsncsEka/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Ramses Technical Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#161718\">\u003clink data-mint-head rel=\"canonical\" href=\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/contracts/reference/core/libraries/SwapMath.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://tech.ramses.xyz/#organization\",\"name\":\"Ramses Technical Documentation\",\"url\":\"https://tech.ramses.xyz\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/ramses/nvKKukknXVTxMy0x/images/logo.png?fit=max\u0026auto=format\u0026n=nvKKukknXVTxMy0x\u0026q=85\u0026s=8baedca01f01eb1da8b939c567f92483\"}},{\"@type\":\"WebSite\",\"@id\":\"https://tech.ramses.xyz#website\",\"name\":\"Ramses Technical Documentation\",\"url\":\"https://tech.ramses.xyz\",\"publisher\":{\"@id\":\"https://tech.ramses.xyz/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath#webpage\",\"url\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath\",\"name\":\"SwapMath\",\"dateModified\":\"2026-08-16T19:46:43.575Z\",\"isPartOf\":{\"@id\":\"https://tech.ramses.xyz#website\"},\"breadcrumb\":{\"@id\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Reference\",\"item\":\"https://tech.ramses.xyz/contracts/reference/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Core Libraries\",\"item\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/BitMath\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SwapMath\",\"item\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath#article\",\"headline\":\"SwapMath\",\"name\":\"SwapMath\",\"url\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath\",\"mainEntityOfPage\":{\"@id\":\"https://tech.ramses.xyz/contracts/reference/core/libraries/SwapMath#webpage\"},\"dateModified\":\"2026-08-16T19:46:43.575Z\",\"publisher\":{\"@id\":\"https://tech.ramses.xyz/#organization\"},\"isPartOf\":{\"@id\":\"https://tech.ramses.xyz#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Ramses Technical Documentation\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Ramses Technical Documentation","nav":{"global":null,"tabs":[{"tab":"Concepts","icon":"book-open","groups":[{"group":"Overview","icon":"map","pages":[{"title":"Concepts Overview","href":"/concepts/overview"},{"title":"Ramses Overview","href":"/concepts/what-is-ramses"},{"title":"The Ramses Protocol","href":"/concepts/ramses-protocol"},{"title":"Token Contracts \u0026 Tokenomics","href":"/concepts/tokenomics"}]},{"group":"Protocol Mechanics","icon":"cpu","pages":[{"title":"Concentrated Liquidity \u0026 Period-Based Accounting","href":"/concepts/protocol/concentrated-liquidity"},{"title":"DLMM \u0026 Liquidity Bins","href":"/concepts/protocol/dlmm"},{"title":"Swaps","href":"/concepts/protocol/swaps"},{"title":"Fees","href":"/concepts/protocol/fees"},{"title":"Oracle","href":"/concepts/protocol/oracle"},{"title":"Range Orders","href":"/concepts/protocol/range-orders"},{"title":"Token Integration Issues","href":"/concepts/protocol/integration-issues"}]},{"group":"Resources","icon":"library-big","pages":[{"title":"Glossary","href":"/concepts/glossary"},{"title":"Resources","href":"/concepts/resources"},{"title":"Research","href":"/concepts/research"}]}]},{"tab":"Contracts","icon":"puzzle","groups":[{"group":"Overview","pages":[{"title":"Overview","href":"/contracts/overview"}]},{"group":"Guides","pages":[{"title":"Set Up Your Local Environment","href":"/contracts/guides/local-environment"},{"group":"Swaps","pages":[{"title":"Single Swaps","href":"/contracts/guides/swaps/single-swaps"},{"title":"Multihop Swaps","href":"/contracts/guides/swaps/multihop-swaps"}]},{"group":"Providing Liquidity","pages":[{"title":"Set Up Your Contract","href":"/contracts/guides/providing-liquidity/setting-up-your-contract"},{"title":"Mint a New Position","href":"/contracts/guides/providing-liquidity/mint-a-new-position"},{"title":"Increase Liquidity","href":"/contracts/guides/providing-liquidity/increase-liquidity"},{"title":"Decrease Liquidity","href":"/contracts/guides/providing-liquidity/decrease-liquidity"},{"title":"Collecting Fees","href":"/contracts/guides/providing-liquidity/collect-fees"},{"title":"The Full Contract","href":"/contracts/guides/providing-liquidity/the-full-contract"}]},{"group":"DLMM","pages":[{"title":"Integrating DLMM","href":"/contracts/guides/dlmm/integration"}]},{"group":"Flash Integrations","pages":[{"title":"Getting Started","href":"/contracts/guides/flash-integrations/inheritance-constructors"},{"title":"Calling Flash","href":"/contracts/guides/flash-integrations/calling-flash"},{"title":"The Flash Callback","href":"/contracts/guides/flash-integrations/flash-callback"},{"title":"The Final Contract","href":"/contracts/guides/flash-integrations/final-contract"}]}]},{"group":"Reference","pages":[{"title":"Overview","href":"/contracts/reference/overview"},{"title":"Error Codes","href":"/contracts/reference/error-codes"},{"group":"Core Contracts","pages":[{"title":null,"href":"/contracts/reference/core/RamsesV3Pool"},{"title":null,"href":"/contracts/reference/core/RamsesV3Factory"},{"title":null,"href":"/contracts/reference/core/RamsesV3PoolDeployer"}]},{"group":"Core Interfaces","pages":[{"title":null,"href":"/contracts/reference/core/interfaces/IRamsesV3Pool"},{"title":null,"href":"/contracts/reference/core/interfaces/IRamsesV3Factory"},{"title":null,"href":"/contracts/reference/core/interfaces/IRamsesV3PoolDeployer"},{"title":null,"href":"/contracts/reference/core/interfaces/IERC20Minimal"},{"group":"Pool Interfaces","expanded":false,"pages":[{"title":null,"href":"/contracts/reference/core/interfaces/pool/IRamsesV3PoolActions"},{"title":null,"href":"/contracts/reference/core/interfaces/pool/IRamsesV3PoolState"},{"title":null,"href":"/contracts/reference/core/interfaces/pool/IRamsesV3PoolDerivedState"},{"title":null,"href":"/contracts/reference/core/interfaces/pool/IRamsesV3PoolEvents"},{"title":null,"href":"/contracts/reference/core/interfaces/pool/IRamsesV3PoolImmutables"},{"title":null,"href":"/contracts/reference/core/interfaces/pool/IRamsesV3PoolOwnerActions"}]},{"group":"Callback Interfaces","expanded":false,"pages":[{"title":null,"href":"/contracts/reference/core/interfaces/callback/IUniswapV3SwapCallback"},{"title":null,"href":"/contracts/reference/core/interfaces/callback/IUniswapV3MintCallback"},{"title":null,"href":"/contracts/reference/core/interfaces/callback/IUniswapV3FlashCallback"}]}]},{"group":"Core Libraries","expanded":false,"pages":[{"title":null,"href":"/contracts/reference/core/libraries/BitMath"},{"title":null,"href":"/contracts/reference/core/libraries/FixedPoint128"},{"title":null,"href":"/contracts/reference/core/libraries/FixedPoint96"},{"title":null,"href":"/contracts/reference/core/libraries/FullMath"},{"title":null,"href":"/contracts/reference/core/libraries/Oracle"},{"title":null,"href":"/contracts/reference/core/libraries/Position"},{"title":null,"href":"/contracts/reference/core/libraries/SafeCast"},{"title":null,"description":null,"href":"/contracts/reference/core/libraries/SqrtPriceMath"},{"title":null,"href":"/contracts/reference/core/libraries/SwapMath"},{"title":null,"description":null,"href":"/contracts/reference/core/libraries/Tick"},{"title":null,"href":"/contracts/reference/core/libraries/TickBitmap"},{"title":null,"href":"/contracts/reference/core/libraries/TickMath"},{"title":null,"href":"/contracts/reference/core/libraries/TransferHelper"},{"title":null,"href":"/contracts/reference/core/libraries/UnsafeMath"}]},{"group":"Periphery Contracts","pages":[{"title":null,"href":"/contracts/reference/periphery/RamsesV3PositionManager"},{"title":null,"href":"/contracts/reference/periphery/NonfungibleTokenPositionDescriptor"},{"title":null,"href":"/contracts/reference/periphery/SwapRouter"}]},{"group":"Periphery Interfaces","expanded":false,"pages":[{"title":null,"href":"/contracts/reference/periphery/interfaces/IRamsesV3PositionManager"},{"title":null,"href":"/contracts/reference/periphery/interfaces/INonfungibleTokenPositionDescriptor"},{"title":null,"href":"/contracts/reference/periphery/interfaces/ISwapRouter"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IQuoter"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IQuoterV2"},{"title":null,"href":"/contracts/reference/periphery/interfaces/ITickLens"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IMulticall"},{"title":null,"href":"/contracts/reference/periphery/interfaces/ISelfPermit"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IPoolInitializer"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IPeripheryImmutableState"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IPeripheryPayments"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IPeripheryPaymentsWithFee"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IERC20Metadata"},{"title":null,"href":"/contracts/reference/periphery/interfaces/IERC721Permit"},{"title":null,"href":"/contracts/reference/periphery/interfaces/external/IERC1271"},{"title":null,"href":"/contracts/reference/periphery/interfaces/external/IERC20PermitAllowed"},{"title":null,"href":"/contracts/reference/periphery/interfaces/external/IWETH9"}]},{"group":"Periphery Base","expanded":false,"pages":[{"title":null,"href":"/contracts/reference/periphery/base/BlockTimestamp"},{"title":null,"href":"/contracts/reference/periphery/base/ERC721Permit"},{"title":null,"href":"/contracts/reference/periphery/base/LiquidityManagement"},{"title":null,"href":"/contracts/reference/periphery/base/Multicall"},{"title":null,"href":"/contracts/reference/periphery/base/PeripheryImmutableState"},{"title":null,"href":"/contracts/reference/periphery/base/PeripheryPayments"},{"title":null,"href":"/contracts/reference/periphery/base/PeripheryPaymentsWithFee"},{"title":null,"href":"/contracts/reference/periphery/base/PoolInitializer"},{"title":null,"href":"/contracts/reference/periphery/base/SelfPermit"}]},{"group":"Periphery Lens","pages":[{"title":null,"href":"/contracts/reference/periphery/lens/TickLens"},{"title":null,"href":"/contracts/reference/periphery/lens/Quoter"},{"title":null,"href":"/contracts/reference/periphery/lens/QuoterV2"}]},{"group":"Periphery Libraries","expanded":false,"pages":[{"title":null,"href":"/contracts/reference/periphery/libraries/Base64"},{"title":null,"href":"/contracts/reference/periphery/libraries/BytesLib"},{"title":null,"href":"/contracts/reference/periphery/libraries/ChainId"},{"title":null,"href":"/contracts/reference/periphery/libraries/HexStrings"},{"title":null,"href":"/contracts/reference/periphery/libraries/LiquidityAmounts"},{"title":null,"href":"/contracts/reference/periphery/libraries/NFTDescriptor"},{"title":null,"href":"/contracts/reference/periphery/libraries/NFTSVG"},{"title":null,"href":"/contracts/reference/periphery/libraries/Path"},{"title":null,"href":"/contracts/reference/periphery/libraries/PoolTicksCounter"},{"title":null,"href":"/contracts/reference/periphery/libraries/PositionKey"},{"title":null,"href":"/contracts/reference/periphery/libraries/TokenRatioSortOrder"},{"title":null,"href":"/contracts/reference/periphery/libraries/TransferHelper"}]},{"group":"Gauge \u0026 Fees","pages":[{"title":null,"href":"/contracts/reference/gauge/GaugeV3"},{"title":null,"href":"/contracts/reference/gauge/FeeCollector"},{"title":null,"href":"/contracts/reference/gauge/FeeDistributor"},{"title":"Sarcophagus","icon":"tombstone","href":"/contracts/reference/sarcophagus"}]},{"group":"DLMM","pages":[{"title":"DLMM Contract Architecture","href":"/contracts/reference/dlmm/overview"},{"title":"Robinhood DLMM Deployments","href":"/contracts/reference/dlmm/deployments"}]},{"group":"Governance","pages":[{"title":null,"href":"/contracts/reference/governance/Voter"},{"title":null,"href":"/contracts/reference/governance/Minter"},{"title":null,"href":"/contracts/reference/governance/VoteModule"},{"title":null,"href":"/contracts/reference/governance/AccessHub"}]},{"group":"Tokens","pages":[{"title":null,"href":"/contracts/reference/tokens/xRAM"},{"title":null,"href":"/contracts/reference/tokens/R33"}]},{"group":"Deployments","pages":[{"title":"Deployment Addresses","href":"/contracts/reference/deployments/deployments"}]}]}]},{"tab":"API Reference","icon":"server","groups":[{"group":"Overview","pages":[{"title":"Ramses API","href":"/users-api-reference/overview"}]}]},{"tab":"SDKs","icon":"code","groups":[{"group":"Overview","pages":[{"title":"Overview","href":"/sdk/overview"}]},{"group":"Getting Started","pages":[{"title":"Background","href":"/sdk/guides/01-background"},{"title":"Local Development","href":"/sdk/guides/02-local-development"},{"title":"Web3 Development Basics","href":"/sdk/guides/03-web3-development-basics"}]},{"group":"Swaps","pages":[{"title":"Getting a Quote","href":"/sdk/guides/swaps/01-quoting"},{"title":"Executing a Trade","href":"/sdk/guides/swaps/02-trading"},{"title":"Routing a Swap","href":"/sdk/guides/swaps/03-routing"}]},{"group":"Liquidity","pages":[{"title":"Liquidity Positions","href":"/sdk/guides/liquidity/01-position-data"},{"title":"Minting a Position","href":"/sdk/guides/liquidity/02-minting-position"},{"title":"Fetching Positions","href":"/sdk/guides/liquidity/03-fetching-positions"},{"title":"Adding \u0026 Removing Liquidity","href":"/sdk/guides/liquidity/04-modifying-position"},{"title":"Collecting Fees","href":"/sdk/guides/liquidity/05-collecting-fees"},{"title":"Swapping and Adding Liquidity","href":"/sdk/guides/liquidity/06-swap-and-add-liquidity"}]},{"group":"Advanced","pages":[{"title":"Introduction","href":"/sdk/guides/advanced/01-introduction"},{"title":"Fetching Pool Data","href":"/sdk/guides/advanced/02-pool-data"},{"title":"Active Liquidity","href":"/sdk/guides/advanced/03-active-liquidity"},{"title":"Ramses V3 as a Price Oracle","href":"/sdk/guides/advanced/04-price-oracle"},{"title":"Range Orders","href":"/sdk/guides/advanced/05-range-orders"}]}]}]},"title":"SwapMath - Ramses Technical Documentation","buildId":"dpl_HcHmUS6i3UwswnTHJUEdcTtwfdTQ","deploymentId":"dpl_HcHmUS6i3UwswnTHJUEdcTtwfdTQ","dynamics":[],"chunks":[]}