UNPKG

@admin-jigsaw/jigsaw-sdk

Version:

Returns predefined data for Jigsaw platform and exposes functionality to retrieve the necessary data

101 lines (100 loc) 5.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const index_1 = require("../index"); const chains_1 = require("viem/chains"); const testClient_1 = require("./utils/testClient"); // Mock the dependencies vitest_1.vi.mock("../constants/chains"); vitest_1.vi.mock("../utils/protocols.utils", () => ({ getProtocolByStrategy: vitest_1.vi.fn().mockReturnValue("AAVE"), })); vitest_1.vi.mock("../utils/pendle.utils", () => ({ generatePendleRemoveLiquidityDataString: vitest_1.vi .fn() .mockResolvedValue("0xmockdata"), getPendleMarketByStrategy: vitest_1.vi.fn().mockReturnValue("0xmockmarket"), })); vitest_1.vi.mock("../lib/pendle", () => ({ removeLiquiditySingleToken: vitest_1.vi .fn() .mockResolvedValue({ mockResponse: "data" }), })); (0, vitest_1.describe)("JigsawClient Liquidation Info", () => { let client; let mockReadContract; let mockMulticall; (0, vitest_1.beforeEach)(() => { client = new index_1.JigsawClient("http://localhost:8545", chains_1.mainnet.id); mockReadContract = vitest_1.vi.fn(); mockMulticall = vitest_1.vi.fn(); client.client.readContract = mockReadContract; client.client.multicall = mockMulticall; // Mock getUserStrategies to return consistent results vitest_1.vi.spyOn(client, "getUserStrategies").mockResolvedValue([ testClient_1.MOCK_STRATEGY_ADDRESS_1, ]); }); (0, vitest_1.describe)("getUserLiquidationInfo", () => { (0, vitest_1.it)("should handle symbols with special characters in liquidation info", async () => { // Mock the multicall response for strategy info mockMulticall.mockResolvedValue([ { result: [BigInt(0), BigInt(1000000)] }, // recipients result { result: "0x1234567890123456789012345678901234567890" }, // tokenIn result ]); const result = await client.getUserLiquidationInfo(testClient_1.MOCK_HOLDING_ADDRESS, "USD0++"); (0, vitest_1.expect)(result.strategies).toEqual([testClient_1.MOCK_STRATEGY_ADDRESS_1]); (0, vitest_1.expect)(result.strategiesData).toHaveLength(1); (0, vitest_1.expect)(client.getUserStrategies).toHaveBeenCalledWith(testClient_1.MOCK_HOLDING_ADDRESS, "USD0++"); }); (0, vitest_1.it)("should handle USDC.e symbol for sonic chain", async () => { const sonicClient = new index_1.JigsawClient("http://localhost:8545", chains_1.sonic.id); sonicClient.client.multicall = mockMulticall; vitest_1.vi.spyOn(sonicClient, "getUserStrategies").mockResolvedValue([ testClient_1.MOCK_STRATEGY_ADDRESS_1, ]); mockMulticall.mockResolvedValue([ { result: [BigInt(0), BigInt(1000000)] }, { result: "0x1234567890123456789012345678901234567890" }, ]); const result = await sonicClient.getUserLiquidationInfo(testClient_1.MOCK_HOLDING_ADDRESS, "USDC.e"); (0, vitest_1.expect)(result.strategies).toEqual([testClient_1.MOCK_STRATEGY_ADDRESS_1]); (0, vitest_1.expect)(sonicClient.getUserStrategies).toHaveBeenCalledWith(testClient_1.MOCK_HOLDING_ADDRESS, "USDC.e"); }); (0, vitest_1.it)("should handle case insensitive symbols in liquidation info", async () => { mockMulticall.mockResolvedValue([ { result: [BigInt(0), BigInt(1000000)] }, { result: "0x1234567890123456789012345678901234567890" }, ]); const result = await client.getUserLiquidationInfo(testClient_1.MOCK_HOLDING_ADDRESS, "usd0++"); (0, vitest_1.expect)(result.strategies).toEqual([testClient_1.MOCK_STRATEGY_ADDRESS_1]); (0, vitest_1.expect)(client.getUserStrategies).toHaveBeenCalledWith(testClient_1.MOCK_HOLDING_ADDRESS, "usd0++"); }); (0, vitest_1.it)("should handle empty strategies array gracefully", async () => { vitest_1.vi.spyOn(client, "getUserStrategies").mockResolvedValue([]); const result = await client.getUserLiquidationInfo(testClient_1.MOCK_HOLDING_ADDRESS, "USD0++"); (0, vitest_1.expect)(result.strategies).toEqual([]); (0, vitest_1.expect)(result.strategiesData).toEqual([]); }); (0, vitest_1.it)("should pass through pendleSlippage parameter correctly", async () => { mockMulticall.mockResolvedValue([ { result: [BigInt(0), BigInt(1000000)] }, { result: "0x1234567890123456789012345678901234567890" }, ]); const customSlippage = 0.02; // 2% await client.getUserLiquidationInfo(testClient_1.MOCK_HOLDING_ADDRESS, "USD0++", customSlippage); (0, vitest_1.expect)(client.getUserStrategies).toHaveBeenCalledWith(testClient_1.MOCK_HOLDING_ADDRESS, "USD0++"); }); (0, vitest_1.it)("should handle errors in strategy processing gracefully", async () => { vitest_1.vi.spyOn(client, "getUserStrategies").mockResolvedValue([ testClient_1.MOCK_STRATEGY_ADDRESS_1, ]); mockMulticall.mockRejectedValue(new Error("Multicall failed")); const result = await client.getUserLiquidationInfo(testClient_1.MOCK_HOLDING_ADDRESS, "USD0++"); (0, vitest_1.expect)(result.strategies).toEqual([testClient_1.MOCK_STRATEGY_ADDRESS_1]); (0, vitest_1.expect)(result.strategiesData).toEqual([ "0x0000000000000000000000000000000000000000", ]); // zeroAddress for error case }); }); });