@swapnet-xyz/sdk
Version:
TypeScript SDK for SwapNet API.
38 lines (37 loc) • 1.22 kB
JavaScript
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
};
};