Skip to content

Commit

Permalink
fix: getQuote should work with ZETA (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Jul 10, 2024
1 parent 3ada76c commit 748c254
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions packages/client/src/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,37 +144,43 @@ export const getWithdrawFeeInInputToken = async function (
export const getQuote = async function (
this: ZetaChainClient,
inputAmount: string,
inputZRC20: string,
outputZRC20: string
inputToken: string,
outputToken: string
) {
const rpc = this.getEndpoint("evm", "zeta_testnet");
const provider = new ethers.providers.JsonRpcProvider(rpc);
const zetaToken = getZetaToken();

const inputContract = new ethers.Contract(inputZRC20, ZRC20.abi, provider);
const outputContract = new ethers.Contract(outputZRC20, ZRC20.abi, provider);
const inputContract = new ethers.Contract(inputToken, ZRC20.abi, provider);
const outputContract = new ethers.Contract(outputToken, ZRC20.abi, provider);

const inputDecimals = await inputContract.decimals();
const amountIn = parseUnits(inputAmount, inputDecimals).toString();
const outputDecimals = await outputContract.decimals();

const outputAmountInZETA = await getAmounts(
"out",
provider,
amountIn,
inputZRC20,
zetaToken
);
let out;

const outputAmount = await getAmounts(
"out",
provider,
outputAmountInZETA[1],
zetaToken,
outputZRC20
);
if (inputToken === zetaToken || outputToken === zetaToken) {
out = await getAmounts("out", provider, amountIn, inputToken, outputToken);
} else {
const outInZETA = await getAmounts(
"out",
provider,
amountIn,
inputToken,
zetaToken
);

out = await getAmounts(
"out",
provider,
outInZETA[1],
zetaToken,
outputToken
);
}

return { amount: outputAmount[1], decimals: outputDecimals };
return { amount: out[1], decimals: outputDecimals };
};

/**
Expand Down

0 comments on commit 748c254

Please sign in to comment.