Skip to content

Commit

Permalink
test: remove hardcoded collateral amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Jan 7, 2025
1 parent 241b530 commit 6488c9e
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions packages/liquidation-sdk-viem/test/examples/preLiquidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
import { BLUE_API_BASE_URL, format } from "@morpho-org/morpho-ts";
import type { BuildTxInput } from "@paraswap/sdk";

import { blueAbi, fetchMarket, fetchToken } from "@morpho-org/blue-sdk-viem";
import {
blueAbi,
fetchAccrualPosition,
fetchMarket,
fetchToken,
} from "@morpho-org/blue-sdk-viem";
import {
Flashbots,
type LiquidationEncoder,
Expand All @@ -23,6 +28,7 @@ import type { mainnet } from "viem/chains";
import { afterEach, beforeEach, describe, expect, vi } from "vitest";
import { check } from "../../examples/whitelistedMarkets.js";
import { OneInch, Paraswap, Pendle } from "../../src/index.js";
import { PreLiquidationPosition } from "../../src/preLiquidation/types.js";
import * as swapMock from "../contracts/SwapMock.js";
import pendleMarketData from "../pendleMockData/pendleMarketData.json";
import pendleTokens from "../pendleMockData/pendleTokens.json";
Expand Down Expand Up @@ -343,7 +349,22 @@ describe("pre liquidation", () => {
],
});

await syncTimestamp(client);
const timestamp = await syncTimestamp(client);

const loanAssetApiData = {
address: market.params.loanToken,
decimals: loanToken.decimals,
priceUsd: null,
spotPriceEth: 1 / ethPriceUsd,
symbol: loanToken.symbol!,
};
const collateralAssetApiData = {
address: market.params.collateralToken,
decimals: collateralToken.decimals,
priceUsd: collateralPriceUsd,
spotPriceEth: collateralPriceUsd / ethPriceUsd,
symbol: collateralToken.symbol!,
};

nock(BLUE_API_BASE_URL)
.post("/graphql")
Expand Down Expand Up @@ -407,11 +428,35 @@ describe("pre liquidation", () => {
},
});

const accrualPosition = await fetchAccrualPosition(
borrower.address,
marketId,
client,
);

const accruedPosition = accrualPosition.accrueInterest(timestamp);

const preLiquidablePosition = new PreLiquidationPosition(
accruedPosition,
collateralAssetApiData,
loanAssetApiData,
{
marketId,
address: preLiquidationAddress,
preLiquidationParams,
},
);

const preSeizableCollateral =
preLiquidablePosition.preSeizableCollateral!;

console.log("preSeizableCollateral", preSeizableCollateral);

mockOneInch(encoder, [
{ srcAmount: 68612722n, dstAmount: "67941555868" },
{ srcAmount: preSeizableCollateral, dstAmount: "67941555868" },
]);
mockParaSwap(encoder, [
{ srcAmount: 68612722n, dstAmount: "67941555868" },
{ srcAmount: preSeizableCollateral, dstAmount: "67941555868" },
]);

await check(encoder.address, client, client.account, [marketId]);
Expand Down

0 comments on commit 6488c9e

Please sign in to comment.