Skip to content

Commit

Permalink
Fix: increase exit pool slippage with high precision amounts (#3858)
Browse files Browse the repository at this point in the history
* increase exit pool slippage

* remove log

* comment
  • Loading branch information
jonator authored Sep 26, 2024
1 parent fefd949 commit 071740b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/stores/src/account/osmosis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
);
Expand Down

0 comments on commit 071740b

Please sign in to comment.