Skip to content

Commit

Permalink
fix(SOL-jup): remove exactOut from jup
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKozAllB committed Dec 27, 2023
1 parent 1970671 commit fba0359
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/services/bridge/sol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ export class SolanaBridgeService extends ChainBridgeService {
let jupTx;
if (isJupiterForStableCoin) {
try {
let amountToSwap = Big(solTxSendParams.fee);
if (solTxSendParams.extraGas) {
amountToSwap = amountToSwap.plus(solTxSendParams.extraGas);
}

solTxSendParams = await this.convertStableCoinFeeAndExtraGasToNativeCurrency(
params.sourceToken.decimals,
solTxSendParams
);

let amountToGet = Big(solTxSendParams.fee);
if (solTxSendParams.extraGas) {
amountToGet = amountToGet.plus(solTxSendParams.extraGas);
}

const { tx, amountIn } = await this.jupiterService.getJupiterSwapTx(
const { tx } = await this.jupiterService.getJupiterSwapTx(
params.fromAccountAddress,
params.sourceToken.tokenAddress,
amountToGet.toFixed(0)
amountToSwap.toFixed(0)
);
jupTx = tx;
solTxSendParams.amount = Big(solTxSendParams.amount).minus(amountIn).toFixed(0);
solTxSendParams.amount = Big(solTxSendParams.amount).minus(amountToSwap).toFixed(0);
if (Big(solTxSendParams.amount).lte(0)) {
throw new AmountNotEnoughError(
`Amount not enough to pay fee, ${convertIntAmountToFloat(
Expand Down
16 changes: 4 additions & 12 deletions src/services/bridge/sol/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ export class JupiterService {
async getJupiterSwapTx(
userAddress: string,
stableTokenAddress: string,
amountOut: string
): Promise<{ tx: VersionedTransaction; amountIn: string }> {
amount: string
): Promise<{ tx: VersionedTransaction }> {
let quoteResponse: any;
try {
quoteResponse = await axios.get(`https://quote-api.jup.ag/v6/quote?inputMint=${stableTokenAddress}
&outputMint=${NATIVE_MINT.toString()}
&amount=${amountOut}
&swapMode=ExactOut
&amount=${amount}
&slippageBps=100
&onlyDirectRoutes=true`);
} catch (err) {
Expand All @@ -31,13 +30,6 @@ export class JupiterService {
throw new JupiterError("Cannot get route");
}

let inAmount;
if (quoteResponse?.data?.inAmount) {
inAmount = quoteResponse.data.inAmount;
} else {
throw new JupiterError("Cannot get inAmount");
}

let transactionResponse: any;
try {
transactionResponse = await axios.post(
Expand All @@ -63,7 +55,7 @@ export class JupiterService {
}

const swapTransactionBuf = Buffer.from(swapTransaction, "base64");
return { tx: VersionedTransaction.deserialize(swapTransactionBuf), amountIn: inAmount };
return { tx: VersionedTransaction.deserialize(swapTransactionBuf) };
}

async amendJupiterWithSdkTx(
Expand Down

0 comments on commit fba0359

Please sign in to comment.