diff --git a/sdk/package-lock.json b/sdk/package-lock.json index 039a77f3..268a53b2 100644 --- a/sdk/package-lock.json +++ b/sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@invariant-labs/sdk", - "version": "0.9.69", + "version": "0.9.70", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@invariant-labs/sdk", - "version": "0.9.69", + "version": "0.9.70", "dependencies": { "@project-serum/anchor": "0.21.0", "@solana/spl-token-registry": "^0.2.4484", @@ -22,9 +22,10 @@ } }, "node_modules/@babel/runtime": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.7.tgz", - "integrity": "sha512-FjoyLe754PMiYsFaN5C94ttGiOmBNYTf6pLr4xXHAT5uctHb092PBszndLDR5XA/jghQvn4n7JMHl7dmTgbm9w==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.0.tgz", + "integrity": "sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==", + "license": "MIT", "dependencies": { "regenerator-runtime": "^0.14.0" }, @@ -33,11 +34,12 @@ } }, "node_modules/@noble/curves": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.6.0.tgz", - "integrity": "sha512-TlaHRXDehJuRNR9TfZDNQ45mMEd5dwUwmicsafcIX4SsNiqnCHKjE/1alYPd/lDRVhxdhUAlv8uEhMCI5zjIJQ==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.7.0.tgz", + "integrity": "sha512-UTMhXK9SeDhFJVrHeUJ5uZlI6ajXg10O6Ddocf9S6GjbSBVZsJo88HzKwXznNfGpMTRDyJkqMjNDPYgf0qFWnw==", + "license": "MIT", "dependencies": { - "@noble/hashes": "1.5.0" + "@noble/hashes": "1.6.0" }, "engines": { "node": "^14.21.3 || >=16" @@ -46,10 +48,23 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/@noble/curves/node_modules/@noble/hashes": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.0.tgz", + "integrity": "sha512-YUULf0Uk4/mAA89w+k3+yUYh6NrEvxZa5T6SY3wlMvE2chHkxFUUIDI8/XW1QSC357iA5pSnqt7XEhvFOqmDyQ==", + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@noble/hashes": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.5.0.tgz", - "integrity": "sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.1.tgz", + "integrity": "sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==", + "license": "MIT", "engines": { "node": "^14.21.3 || >=16" }, @@ -149,6 +164,7 @@ "version": "1.87.6", "resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.87.6.tgz", "integrity": "sha512-LkqsEBgTZztFiccZZXnawWa8qNCATEqE97/d0vIwjTclmVlc8pBpD1DmjfVHtZ1HS5fZorFlVhXfpwnCNDZfyg==", + "license": "MIT", "dependencies": { "@babel/runtime": "^7.23.2", "@noble/curves": "^1.2.0", @@ -176,6 +192,7 @@ "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "license": "MIT", "dependencies": { "@types/node": "*" } @@ -194,12 +211,14 @@ "node_modules/@types/node": { "version": "12.20.55", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", - "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==" + "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", + "license": "MIT" }, "node_modules/@types/ws": { "version": "7.4.7", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", + "license": "MIT", "dependencies": { "@types/node": "*" } @@ -214,6 +233,7 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "license": "MIT", "dependencies": { "humanize-ms": "^1.2.1" }, @@ -354,6 +374,7 @@ "version": "0.7.0", "resolved": "https://registry.npmjs.org/borsh/-/borsh-0.7.0.tgz", "integrity": "sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==", + "license": "Apache-2.0", "dependencies": { "bn.js": "^5.2.0", "bs58": "^4.0.0", @@ -434,6 +455,7 @@ "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz", "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==", "hasInstallScript": true, + "license": "MIT", "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" @@ -597,7 +619,8 @@ "node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "license": "MIT" }, "node_modules/concat-map": { "version": "0.0.1", @@ -689,6 +712,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/delay/-/delay-5.0.0.tgz", "integrity": "sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==", + "license": "MIT", "engines": { "node": ">=10" }, @@ -730,12 +754,14 @@ "node_modules/es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "license": "MIT" }, "node_modules/es6-promisify": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", "integrity": "sha512-C+d6UdsYDk0lMebHNR4S2NybQMMngAOnOwYBQjTOiv0MkoJMP0Myw2mgpDLBcpfCmRLxyFqYhS/CfOENq4SJhQ==", + "license": "MIT", "dependencies": { "es6-promise": "^4.0.3" } @@ -910,6 +936,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "license": "MIT", "dependencies": { "ms": "^2.0.0" } @@ -1018,14 +1045,16 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz", "integrity": "sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==", + "license": "MIT", "peerDependencies": { "ws": "*" } }, "node_modules/jayson": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/jayson/-/jayson-4.1.2.tgz", - "integrity": "sha512-5nzMWDHy6f+koZOuYsArh2AXs73NfWYVlFyJJuCedr93GpY+Ku8qq10ropSXVfHK+H0T6paA88ww+/dV+1fBNA==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/jayson/-/jayson-4.1.3.tgz", + "integrity": "sha512-LtXh5aYZodBZ9Fc3j6f2w+MTNcnxteMOrb+QgIouguGOulWi0lieEkOUg+HkjjFs0DGoWDds6bi4E9hpNFLulQ==", + "license": "MIT", "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", @@ -1066,7 +1095,8 @@ "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==" + "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", + "license": "ISC" }, "node_modules/json5": { "version": "1.0.2", @@ -1086,12 +1116,14 @@ "integrity": "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==", "engines": [ "node >= 0.2.0" - ] + ], + "license": "MIT" }, "node_modules/JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", "integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==", + "license": "(MIT OR Apache-2.0)", "dependencies": { "jsonparse": "^1.2.0", "through": ">=2.2.7 <3" @@ -1252,6 +1284,7 @@ "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -1268,9 +1301,10 @@ } }, "node_modules/node-gyp-build": { - "version": "4.8.2", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.2.tgz", - "integrity": "sha512-IRUxE4BVsHWXkV/SFOut4qTlagw2aM8T5/vnTsmrHJvVoKueJHRc/JaFND7QDDc61kLYUJ6qlZM3sqTSyx2dTw==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", + "license": "MIT", "optional": true, "bin": { "node-gyp-build": "bin.js", @@ -1391,7 +1425,8 @@ "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "license": "MIT" }, "node_modules/require-directory": { "version": "2.1.1", @@ -1406,6 +1441,7 @@ "version": "7.11.2", "resolved": "https://registry.npmjs.org/rpc-websockets/-/rpc-websockets-7.11.2.tgz", "integrity": "sha512-pL9r5N6AVHlMN/vT98+fcO+5+/UcPLf/4tq+WUaid/PPUGS/ttJ3y8e9IqmaWKtShNAysMSjkczuEA49NuV7UQ==", + "license": "LGPL-3.0-only", "dependencies": { "eventemitter3": "^4.0.7", "uuid": "^8.3.2", @@ -1424,6 +1460,7 @@ "version": "8.18.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "license": "MIT", "engines": { "node": ">=10.0.0" }, @@ -1565,7 +1602,8 @@ "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==" + "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", + "license": "MIT" }, "node_modules/to-regex-range": { "version": "5.0.1", @@ -1680,6 +1718,7 @@ "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", "hasInstallScript": true, + "license": "MIT", "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" @@ -1692,6 +1731,7 @@ "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", "bin": { "uuid": "dist/bin/uuid" } @@ -1809,6 +1849,7 @@ "version": "7.5.10", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "license": "MIT", "engines": { "node": ">=8.3.0" }, diff --git a/sdk/package.json b/sdk/package.json index 222470ca..1cb0950e 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@invariant-labs/sdk", - "version": "0.9.69", + "version": "0.9.70", "description": "", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/sdk/src/market.ts b/sdk/src/market.ts index 276e7fb0..3b5b103f 100644 --- a/sdk/src/market.ts +++ b/sdk/src/market.ts @@ -45,6 +45,7 @@ const TICK_SEED = 'tickv1' const POSITION_LIST_SEED = 'positionlistv1' const STATE_SEED = 'statev1' export const TICK_CROSSES_PER_IX = 19 +export const TICK_VIRTUAL_CROSSES_PER_IX = 10 export const FEE_TIER = 'feetierv1' export const DEFAULT_PUBLIC_KEY = new PublicKey(0) diff --git a/sdk/src/utils.ts b/sdk/src/utils.ts index 740cad85..03447297 100644 --- a/sdk/src/utils.ts +++ b/sdk/src/utils.ts @@ -20,7 +20,9 @@ import { PoolData, Errors, PositionInitData, - Position + Position, + TICK_CROSSES_PER_IX, + TICK_VIRTUAL_CROSSES_PER_IX } from './market' import { calculateMinReceivedTokensByAmountIn, @@ -118,6 +120,8 @@ export interface SimulateSwapInterface { ticks: Map tickmap: Tickmap pool: PoolData + maxVirtualCrosses?: number + maxCrosses?: number } export interface Simulation { @@ -482,6 +486,7 @@ export const getCloserLimit = (closerLimit: CloserLimit): CloserLimitResult => { export enum SimulationStatus { Ok, + SwapStepLimitReached = 'Swap step limit reached', WrongLimit = 'Price limit is on the wrong side of price', PriceLimitReached = 'Price would cross swap limit', TickNotFound = 'tick crossed but not passed to simulation', @@ -497,7 +502,9 @@ export const swapSimulation = async ( priceLimit: Decimal, slippage: Decimal, market: Market, - poolAddress: PublicKey + poolAddress: PublicKey, + maxVirtualCrosses?: number, + maxCrosses?: number ): Promise => { const { currentTickIndex, fee, tickSpacing, tokenX, tokenY, liquidity, sqrtPrice } = await market.getPoolByAddress(poolAddress) @@ -528,7 +535,9 @@ export const swapSimulation = async ( slippage, ticks, tickmap, - pool: poolData + pool: poolData, + maxCrosses, + maxVirtualCrosses } return simulateSwap(swapParameters) @@ -545,18 +554,27 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR priceLimit: optionalPriceLimit, pool } = swapParameters + let maxCrosses = swapParameters.maxCrosses ?? TICK_CROSSES_PER_IX + let maxVirtualCrosses = swapParameters.maxVirtualCrosses ?? TICK_VIRTUAL_CROSSES_PER_IX + let { currentTickIndex, tickSpacing, liquidity, sqrtPrice, fee } = pool - const startingSqrtPrice = sqrtPrice.v + const startingSqrtPrice = sqrtPrice let previousTickIndex = MAX_TICK + 1 const amountPerTick: BN[] = [] const crossedTicks: number[] = [] - const priceLimit = - optionalPriceLimit ?? xToY ? calculatePriceSqrt(MIN_TICK) : calculatePriceSqrt(MAX_TICK) + let swapSteps = 0 + let priceLimitAfterSlippage + + if (!optionalPriceLimit) { + priceLimitAfterSlippage = xToY ? calculatePriceSqrt(MIN_TICK) : calculatePriceSqrt(MAX_TICK) + } else { + priceLimitAfterSlippage = calculatePriceAfterSlippage(optionalPriceLimit, slippage, !xToY) + } + let accumulatedAmount: BN = new BN(0) let accumulatedAmountOut: BN = new BN(0) let accumulatedAmountIn: BN = new BN(0) let accumulatedFee: BN = new BN(0) - const priceLimitAfterSlippage = calculatePriceAfterSlippage(priceLimit, slippage, !xToY) // Sanity check, should never throw if (xToY) { @@ -591,6 +609,7 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR byAmountIn, fee ) + swapSteps++ accumulatedAmountIn = accumulatedAmountIn.add(result.amountIn) accumulatedAmountOut = accumulatedAmountOut.add(result.amountOut) @@ -629,10 +648,13 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR // cross if (initialized) { - if (!ticks.has(tickIndex)) { + const tick = ticks.get(tickIndex) + + if (tick === undefined) { throw new Error(SimulationStatus.TickNotFound) } - const tick = ticks.get(tickIndex) as Tick + + crossedTicks.push(tickIndex) if (!xToY || isEnoughAmountToCross) { // trunk-ignore(eslint/no-mixed-operators) @@ -641,7 +663,6 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR } else { liquidity = { v: liquidity.v.sub(tick.liquidityChange.v) } } - crossedTicks.push(tickIndex) } else if (!remainingAmount.eqn(0)) { if (byAmountIn) { accumulatedAmountIn = accumulatedAmountIn.add(remainingAmount) @@ -668,10 +689,8 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR accumulatedAmount = new BN(0) } - // in the future this can be replaced by counter - if (!isTickInitialized && liquidity.v.eqn(0)) { - // throw new Error(SimulationErrors.TooLargeGap) - status = SimulationStatus.TooLargeGap + if (swapSteps > maxCrosses + maxVirtualCrosses || crossedTicks.length > maxCrosses) { + status = SimulationStatus.SwapStepLimitReached break } @@ -689,18 +708,14 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR status = SimulationStatus.NoGainSwap } - const priceAfterSwap: BN = sqrtPrice.v - const priceImpact = calculatePriceImpact(startingSqrtPrice, priceAfterSwap) + const priceAfterSwap = sqrtPrice + const priceImpact = calculatePriceImpact(startingSqrtPrice.v, priceAfterSwap.v) let minReceived: BN if (byAmountIn) { - const endingPriceAfterSlippage = calculatePriceAfterSlippage( - { v: priceAfterSwap }, - slippage, - !xToY - ).v + const endingPriceAfterSlippage = calculatePriceAfterSlippage(priceAfterSwap, slippage, !xToY) minReceived = calculateMinReceivedTokensByAmountIn( - endingPriceAfterSlippage, + endingPriceAfterSlippage.v, xToY, accumulatedAmountIn, pool.fee.v @@ -716,7 +731,7 @@ export const simulateSwap = (swapParameters: SimulateSwapInterface): SimulationR accumulatedAmountIn, accumulatedAmountOut, accumulatedFee, - priceAfterSwap, + priceAfterSwap: priceAfterSwap.v, priceImpact, minReceived }