Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 committed Jan 8, 2025
1 parent fb8c0c6 commit 82fadc3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
8 changes: 4 additions & 4 deletions api/swap/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ export async function handleBaseSwapQueryParams(

const refundToken = refundOnOrigin ? inputToken : outputToken;

// 3. Calculate fees based for full route
const fees = await calculateCrossSwapFees(crossSwapQuotes);

return {
fees,
inputToken,
outputToken,
amount,
Expand Down Expand Up @@ -295,6 +291,7 @@ export function buildBaseSwapResponseJson(params: {
gasPrice: BigNumber;
};
permitSwapTx?: AuthTxPayload | PermitTxPayload;
fees: CrossSwapFees;
}) {
return stringifyBigNumProps({
checks: {
Expand Down Expand Up @@ -328,13 +325,15 @@ export function buildBaseSwapResponseJson(params: {
outputAmount: params.originSwapQuote.expectedAmountOut,
minOutputAmount: params.originSwapQuote.minAmountOut,
maxInputAmount: params.originSwapQuote.maximumAmountIn,
fees: params.fees.originSwapFees,
}
: undefined,
bridge: {
inputAmount: params.bridgeQuote.inputAmount,
outputAmount: params.bridgeQuote.outputAmount,
tokenIn: params.bridgeQuote.inputToken,
tokenOut: params.bridgeQuote.outputToken,
fees: params.fees.bridgeFees,
},
destinationSwap: params.destinationSwapQuote
? {
Expand All @@ -344,6 +343,7 @@ export function buildBaseSwapResponseJson(params: {
maxInputAmount: params.destinationSwapQuote.maximumAmountIn,
outputAmount: params.destinationSwapQuote.expectedAmountOut,
minOutputAmount: params.destinationSwapQuote.minAmountOut,
fees: params.fees.destinationSwapFees,
}
: undefined,
},
Expand Down
10 changes: 6 additions & 4 deletions api/swap/approval/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BaseSwapQueryParams,
getApprovalTxns,
buildBaseSwapResponseJson,
calculateCrossSwapFees,
} from "../_utils";
import { getBalanceAndAllowance } from "../../_erc20";
import { getCrossSwapQuotes } from "../../_dexes/cross-swap-service";
Expand Down Expand Up @@ -77,10 +78,10 @@ const handler = async (
quoteFetchStrategies
);

const crossSwapTx = await buildCrossSwapTxForAllowanceHolder(
crossSwapQuotes,
integratorId
);
const [crossSwapTx, fees] = await Promise.all([
buildCrossSwapTxForAllowanceHolder(crossSwapQuotes, integratorId),
calculateCrossSwapFees(crossSwapQuotes),
]);

const { originSwapQuote, bridgeQuote, destinationSwapQuote, crossSwap } =
crossSwapQuotes;
Expand Down Expand Up @@ -140,6 +141,7 @@ const handler = async (
originChainId,
inputTokenAddress,
inputAmount,
fees,
approvalSwapTx: {
...crossSwapTx,
gas: originTxGas,
Expand Down
15 changes: 10 additions & 5 deletions api/swap/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
handleBaseSwapQueryParams,
BaseSwapQueryParams,
buildBaseSwapResponseJson,
calculateCrossSwapFees,
} from "../_utils";
import { getSwapRouter02Strategy } from "../../_dexes/uniswap/swap-router-02";
import { InvalidParamError } from "../../_errors";
Expand Down Expand Up @@ -109,11 +110,14 @@ const handler = async (
},
});

const balance = await getBalance({
chainId: inputToken.chainId,
tokenAddress: inputToken.address,
owner: crossSwapQuotes.crossSwap.depositor,
});
const [balance, fees] = await Promise.all([
getBalance({
chainId: inputToken.chainId,
tokenAddress: inputToken.address,
owner: crossSwapQuotes.crossSwap.depositor,
}),
calculateCrossSwapFees(crossSwapQuotes),
]);

const responseJson = buildBaseSwapResponseJson({
inputTokenAddress: inputToken.address,
Expand All @@ -127,6 +131,7 @@ const handler = async (
balance,
// Allowance does not matter for auth-based flows
allowance: BigNumber.from(0),
fees,
});

logger.debug({
Expand Down
16 changes: 11 additions & 5 deletions api/swap/permit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
handleBaseSwapQueryParams,
BaseSwapQueryParams,
buildBaseSwapResponseJson,
calculateCrossSwapFees,
} from "../_utils";
import { getSwapRouter02Strategy } from "../../_dexes/uniswap/swap-router-02";
import { InvalidParamError } from "../../_errors";
Expand Down Expand Up @@ -92,6 +93,7 @@ const handler = async (
},
quoteFetchStrategies
);

// Build tx for permit
const crossSwapTxForPermit = await buildPermitTxPayload({
crossSwapQuotes,
Expand All @@ -103,11 +105,14 @@ const handler = async (
},
});

const balance = await getBalance({
chainId: inputToken.chainId,
tokenAddress: inputToken.address,
owner: crossSwapQuotes.crossSwap.depositor,
});
const [balance, fees] = await Promise.all([
getBalance({
chainId: inputToken.chainId,
tokenAddress: inputToken.address,
owner: crossSwapQuotes.crossSwap.depositor,
}),
calculateCrossSwapFees(crossSwapQuotes),
]);

const responseJson = buildBaseSwapResponseJson({
inputTokenAddress: inputToken.address,
Expand All @@ -121,6 +126,7 @@ const handler = async (
balance,
// Allowance does not matter for permit-based flows
allowance: BigNumber.from(0),
fees,
});

logger.debug({
Expand Down

0 comments on commit 82fadc3

Please sign in to comment.