Skip to content

Commit

Permalink
fix: use takeSurplus always
Browse files Browse the repository at this point in the history
  • Loading branch information
Verisana committed Oct 12, 2023
1 parent 50afcec commit 526a999
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/methods/swap/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ export const constructBuildTx = ({
const transactionsURL = `${apiURL}/transactions/${chainId}`;

const buildTx: BuildTx = async (params, options = {}, signal) => {
if ('positiveSlippageToUser' in params) {
if ('takeSurplus' in params) {
throw new Error(
'Cannot use both `positiveSlippageToUser` and `takeSurplus` in `buildTx`. Remove one of the params'
);
}
params.takeSurplus = !params.positiveSlippageToUser;
delete params.positiveSlippageToUser;
}
if (
'priceRoute' in params &&
'destAmount' in params && // isn't provided together with `orders`
Expand Down Expand Up @@ -247,6 +238,19 @@ export const constructBuildTx = ({
}
: params;

const takeSurplus =
params.takeSurplus ?? params.positiveSlippageToUser !== undefined
? !params.positiveSlippageToUser
: undefined;

if ('positiveSlippage' in sanitizedParams) {
// positiveSlippageToUser & takeSurplus together will Error in API
delete sanitizedParams.positiveSlippageToUser;
}
if (takeSurplus !== undefined) {
sanitizedParams.takeSurplus = takeSurplus;
}

const fetchParams: FetcherPostInput = {
url: fetchURL,
method: 'POST',
Expand Down

0 comments on commit 526a999

Please sign in to comment.