Skip to content

Commit

Permalink
test: add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Jan 3, 2025
1 parent f4ca0e5 commit 8744d34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
28 changes: 6 additions & 22 deletions packages/liquidation-sdk-viem/examples/whitelistedMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ export const check = async <

const encoder = new LiquidationEncoder(executorAddress, client);

if (seizableCollateral.preLiquidation)
console.log("seizedAssets", seizedAssets);

let dstAmount = 0n;
// Handle Pendle Tokens
// To retrieve the tokens, we need to call the Pendle API to get the swap calldata
Expand Down Expand Up @@ -254,15 +251,8 @@ export const check = async <
repaidAssets,
);

if (seizableCollateral.preLiquidation)
console.log("result", result);

if (result) {
if (seizableCollateral.preLiquidation)
dstAmount = result.dstAmount;

if (seizableCollateral.preLiquidation)
console.log("dstAmount", dstAmount);
dstAmount = result.dstAmount;
} else {
return;
}
Expand Down Expand Up @@ -304,9 +294,6 @@ export const check = async <
maxUint256,
);

if (seizableCollateral.preLiquidation)
console.log("pre liquidation encoding");

seizableCollateral.preLiquidation
? encoder.preLiquidationPreLiquidate(
position.preLiquidation!.address,
Expand All @@ -324,9 +311,6 @@ export const check = async <
encoder.flush(),
);

if (seizableCollateral.preLiquidation)
console.log("pre liquidation encoded");

const populatedTx = await encoder.encodeExec();
const [gasLimit, blockNumber, txCount, { maxFeePerGas }] =
await Promise.all([
Expand All @@ -343,6 +327,11 @@ export const check = async <
);
const profitUsd = loanToken.toUsd(dstAmount - repaidAssets)!;

if (seizableCollateral.preLiquidation) {
console.log("profitUsd", profitUsd);
console.log("gasLimitUsd", gasLimitUsd);
}

if (gasLimitUsd > profitUsd) {
console.log("no profit");
throw Error(
Expand All @@ -360,9 +349,6 @@ export const check = async <
maxFeePerGas,
};

if (seizableCollateral.preLiquidation)
console.log("transaction", transaction);

if (chainId === ChainId.EthMainnet) {
const signedBundle = await Flashbots.signBundle([
{
Expand All @@ -380,8 +366,6 @@ export const check = async <

return await sendTransaction(client, transaction);
} catch (error) {
if (seizableCollateral.preLiquidation)
console.log("error", error);
console.warn(
`Tried liquidating "${seizedAssets}" collateral ("${withdrawnAssets}" underlying) from "${user}" on market "${market.id}":\n`,
error instanceof Error ? error.stack : error,
Expand Down
4 changes: 0 additions & 4 deletions packages/liquidation-sdk-viem/src/LiquidationEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,13 @@ export class LiquidationEncoder<
usePermit2: false,
});

console.log("bestSwap", bestSwap);

tries.push({ srcAmount, srcToken });

if (!bestSwap)
throw Error("could not fetch swap from both 1inch and paraswap");

dstAmount = BigInt(bestSwap.dstAmount);

console.log(`repaidAssets: ${repaidAssets}, dstAmount: ${dstAmount}`);

if (dstAmount < repaidAssets.wadMulDown(BigInt.WAD + slippage)) {
// If we don't have enough liquidity, we try to swap to the alternative token and retry
if (
Expand Down

0 comments on commit 8744d34

Please sign in to comment.