UNPKG

@swapnet-xyz/sdk

Version:
38 lines (37 loc) 1.22 kB
import { toAmountOutMinimum } from "../utils.js"; export class RouterBase { name; chainId; routerAddress; tokenProxyAddress; constructor(name, chainId, routerAddress, tokenProxyAddress = undefined){ this.name = name; this.chainId = chainId; this.routerAddress = routerAddress; this.tokenProxyAddress = tokenProxyAddress; } } export const resolveEncodeOptions = (routingPlan, options)=>{ let { slippageTolerance, amountOutMinimum, deadline, wrapInput, unwrapOutput } = options; if (slippageTolerance !== undefined && amountOutMinimum !== undefined) { throw new Error(`Conflict encoding options: both 'slippageTolerance' and 'amountOutMinimum' are specified.`); } if (amountOutMinimum === undefined) { if (slippageTolerance === undefined) { slippageTolerance = 0.01; } amountOutMinimum = toAmountOutMinimum(routingPlan.amountOut, slippageTolerance); } if (wrapInput === undefined) { wrapInput = false; } if (unwrapOutput === undefined) { unwrapOutput = false; } return { amountOutMinimum, wrapInput, unwrapOutput, deadline }; };