Skip to content

Commit

Permalink
test: log seized asset
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Dec 20, 2024
1 parent 09fbcae commit 7182e2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 9 additions & 13 deletions packages/liquidation-sdk-viem/examples/whitelistedMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export const check = async <

const encoder = new LiquidationEncoder(executorAddress, client);

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 @@ -252,7 +254,6 @@ export const check = async <
);

if (result) {
console.log("result", result);
dstAmount = result.dstAmount;
} else {
return;
Expand Down Expand Up @@ -287,18 +288,14 @@ export const check = async <

if (loanMorphoAllowance === 0n)
// Allows to handle changes in repaidAssets due to price changes and saves gas.
encoder.erc20Approve(
market.params.loanToken,
seizableCollateral.preLiquidation
? position.preLiquidation!.address
: morpho,
maxUint256,
);

console.log("approving");

encoder.erc20Approve(
market.params.loanToken,
seizableCollateral.preLiquidation
? position.preLiquidation!.address
: morpho,
maxUint256,
);

console.log("preLiquidating");
seizableCollateral.preLiquidation
? encoder.preLiquidationPreLiquidate(
position.preLiquidation!.address,
Expand Down Expand Up @@ -364,7 +361,6 @@ export const check = async <

return await sendTransaction(client, transaction);
} catch (error) {
console.log("error on transaction");
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 @@ -529,15 +529,11 @@ export class LiquidationEncoder<

tries.push({ srcAmount, srcToken });

console.log("bestSwap", bestSwap);

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

dstAmount = BigInt(bestSwap.dstAmount);

console.log("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 7182e2d

Please sign in to comment.