Skip to content

Latest commit

 

History

History
201 lines (143 loc) · 3.74 KB

swap-request.md

File metadata and controls

201 lines (143 loc) · 3.74 KB

Swap Request

All calculations for your swap parameters are DEX specific. For example, the estimated receive might be different on one DEX vs another given the same values due to DEXs using different formulas for their calculations.

Obtaining

dexter.newSwapRequest()
    ...

SwapRequest API

forLiquidityPool(LiquidityPool): SwapRequest Set which Liquidity Pool to swap from.
Using
dexter.newSwapRequest()
    .forLiquidityPool(new LiquidityPool(...))
    ...

withSwapInToken(Token): SwapRequest Set which Token in the pool you are swapping in.
Using
dexter.newSwapRequest()
    .withSwapInToken('lovelace')
    ...

withSwapOutToken(Token): SwapRequest Set which Token in the pool you are swapping out.
Using
dexter.newSwapRequest()
    .withSwapOutToken('lovelace')
    ...

withSwapInAmount(bigint): SwapRequest Set how much you are swapping in.
Using
dexter.newSwapRequest()
    .withSwapInAmount(10_000000n)
    ...

withSwapOutAmount(bigint): SwapRequest Set how much you are swapping out.
Using
dexter.newSwapRequest()
    .withSwapOutAmount(10_000000n)
    ...

withMinimumReceive(bigint): SwapRequest Set the minimum you want to receive.
Using
dexter.newSwapRequest()
    .withMinimumReceive(10_000000n)
    ...

withSlippagePercent(number): SwapRequest Set how much slippage you will tolerate. (Default: 1.0%)
Using
dexter.newSwapRequest()
    .withSlippagePercent(0.5)
    ...

flip(): SwapRequest Flip your swap in and swap out token.

Flipping will only affect the swap in & swap out token if the swap in token was set beforehand.

Using
dexter.newSwapRequest()
    .flip()
    ...

getEstimatedReceive(LiquidityPool?): bigint Get the estimated receive for your swap.

Supplying a liquidity pool will run against the provided pool. This is useful when getting the estimated receive for pools with the same tokens, but on different DEXs.

Using
dexter.newSwapRequest()
    .getEstimatedReceive()

getMinimumReceive(LiquidityPool?): bigint Get the minimum receive for your swap.

Supplying a liquidity pool will run against the provided pool. This is useful when getting the minimum receive for pools with the same tokens, but on different DEXs.

Using
dexter.newSwapRequest()
    .getMinimumReceive()

getPriceImpactPercent(): number Get the price impact percentage for your swap.

Supplying a liquidity pool will run against the provided pool. This is useful when getting the minimum receive for pools with the same tokens, but on different DEXs.

Using
dexter.newSwapRequest()
    .getPriceImpactPercent()

getSwapFees(): SwapFee[] Get the DEX specific fees for your swap.
Using
dexter.newSwapRequest()
    .getSwapFees()

submit(): DexTransaction Finally submit your swap on-chain.
Using
dexter.newSwapRequest()
    ...
    .submit()