Skip to main content

SwapHelper

Table of contents​

Constructors​

Methods​

Constructors​

constructor​

• new SwapHelper(): SwapHelper

Returns​

SwapHelper

Methods​

getAmounts​

▸ getAmounts(bin, fp, activeId, swapForY, amountIn): GetAmountsReturn

Returns the swap amounts in the current bin

Parameters​

NameTypeDescription
binBinThe bin information
fpFeeParametersThe fee parameters
activeIdu32The active id of the pair
swapForYboolWhether you've swapping token X for token Y (true) or token Y for token X (false)
amountInu256The amount sent by the user

Returns​

GetAmountsReturn

GetAmountsReturn: amountInToBin (u256), amountOutOfBin (u256), fees (FeesDistribution)

Defined in​

assembly/libraries/SwapHelper.ts:30


getSwapIn​

▸ getSwapIn(pair, amountOut, swapForY, isQuote?): Result<GetSwapInReturn>

Simulate a swap in

Parameters​

NameTypeDefault valueDescription
pairIPairundefined-
amountOutu256undefinedThe amount of token to receive
swapForYboolundefinedWhether you swap X for Y (true), or Y for X (false)
isQuoteboolfalse-

Returns​

Result<GetSwapInReturn>

GetSwapInReturn: amountIn, feesIn

Defined in​

assembly/libraries/SwapHelper.ts:78


getSwapOut​

▸ getSwapOut(pair, amountIn, swapForY, isQuote?): Result<GetSwapOutReturn>

Simulate a swap out

Parameters​

NameTypeDefault valueDescription
pairIPairundefined-
amountInu256undefinedThe amount of token sent
swapForYboolundefinedWhether you swap X for Y (true), or Y for X (false)
isQuoteboolfalseWhether this is a quote or not (will throw or return an error)

Returns​

Result<GetSwapOutReturn>

GetSwapOutReturn: amountOut, feesIn

Defined in​

assembly/libraries/SwapHelper.ts:158