From 071740bb8401f4b9229edcb3f0ee6120726535fb Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Thu, 26 Sep 2024 15:24:54 -0400 Subject: [PATCH] Fix: increase exit pool slippage with high precision amounts (#3858) * increase exit pool slippage * remove log * comment --- packages/stores/src/account/osmosis/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/stores/src/account/osmosis/index.ts b/packages/stores/src/account/osmosis/index.ts index 6a3fedfa13..c83a0c7784 100644 --- a/packages/stores/src/account/osmosis/index.ts +++ b/packages/stores/src/account/osmosis/index.ts @@ -51,6 +51,7 @@ import { DeliverTxResponse, SignOptions } from "../types"; import { findNewClPositionId } from "./tx-response"; const DEFAULT_SLIPPAGE = "2.5"; +const HIGH_DEFAULT_SLIPPAGE = "15"; export interface OsmosisAccount { osmosis: OsmosisAccountImpl; @@ -1414,7 +1415,7 @@ export class OsmosisAccountImpl { * https://docs.osmosis.zone/developing/modules/spec-gamm.html#exit-pool * @param poolId Id of pool to exit. * @param shareInAmount LP shares to redeem. - * @param maxSlippage Max tolerated slippage. Default: 2.5. + * @param maxSlippage Max tolerated slippage. Default: 2.5, 15 with high precision amounts. * @param memo Transaction memo. * @param onFulfill Callback to handle tx fullfillment given raw response. */ @@ -1444,6 +1445,12 @@ export class OsmosisAccountImpl { makeExitPoolMsg.shareCoinDecimals ); + // If the token amount is very large, indicating high precision, + // increase slippage tolerance to allow for the high precision. + if (poolAssets.some(({ amount }) => amount.length > 18)) { + maxSlippage = HIGH_DEFAULT_SLIPPAGE; + } + const maxSlippageDec = new Dec(maxSlippage).quo( DecUtils.getTenExponentNInPrecisionRange(2) );