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 90cf82e commit 9e0b45f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/liquidation-sdk-viem/examples/whitelistedMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export const check = async <
maxUint256,
);

console.log("pre liquidating");
console.log("pre liquidation encoding");

seizableCollateral.preLiquidation
? encoder.preLiquidationPreLiquidate(
Expand All @@ -319,6 +319,8 @@ export const check = async <
encoder.flush(),
);

console.log("pre liquidation encoded");

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

if (gasLimitUsd > profitUsd)
if (gasLimitUsd > profitUsd) {
console.log("no profit");
throw Error(
`gas cost ($${gasLimitUsd.formatWad(
2,
)}) > profit ($${profitUsd.formatWad(2)})`,
);
}

const transaction = {
...populatedTx,
Expand All @@ -350,6 +354,8 @@ export const check = async <
maxFeePerGas,
};

console.log("transaction", transaction);

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

return await sendTransaction(client, transaction);
} catch (error) {
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

0 comments on commit 9e0b45f

Please sign in to comment.