From 95fb3e544fbb04965a0b4dce7cd734d3d7d1fe78 Mon Sep 17 00:00:00 2001 From: Kyle Scott Date: Mon, 2 Oct 2023 16:32:07 -0400 Subject: [PATCH] get leg data test --- packages/panoptic-sdk/README.md | 1 + packages/panoptic-sdk/biome.json | 5 +- .../publicActions/getPanoptionLegData.test.ts | 98 +++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 packages/panoptic-sdk/src/publicActions/getPanoptionLegData.test.ts diff --git a/packages/panoptic-sdk/README.md b/packages/panoptic-sdk/README.md index 22a30ee..baad0b0 100644 --- a/packages/panoptic-sdk/README.md +++ b/packages/panoptic-sdk/README.md @@ -45,6 +45,7 @@ Typescript SDK for Panoptic - [x] `getPanopticPoolData` - [x] `getPanopticCollateralData` - [x] `getPanopticCollateralPositionData` + - [x] `getPanoptionLegData` - [x] `getPanopticPositionData` - [x] `simulatePanopticDeployNewPool` - [x] `simulatePanopticMintOptions` diff --git a/packages/panoptic-sdk/biome.json b/packages/panoptic-sdk/biome.json index 7eb0575..b4bb312 100644 --- a/packages/panoptic-sdk/biome.json +++ b/packages/panoptic-sdk/biome.json @@ -15,7 +15,10 @@ "linter": { "enabled": true, "rules": { - "recommended": true + "recommended": true, + "style": { + "noNonNullAssertion": "off" + } } } } diff --git a/packages/panoptic-sdk/src/publicActions/getPanoptionLegData.test.ts b/packages/panoptic-sdk/src/publicActions/getPanoptionLegData.test.ts new file mode 100644 index 0000000..1a04d16 --- /dev/null +++ b/packages/panoptic-sdk/src/publicActions/getPanoptionLegData.test.ts @@ -0,0 +1,98 @@ +import { createUniswapV3Tick } from "uniswap-v3-sdk"; +import { type Hex } from "viem"; +import { simulateContract, writeContract } from "viem/actions"; +import { sepolia } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import { ALICE } from "../_test/constants.js"; +import { + deployPool, + publicClient, + testClient, + walletClient, +} from "../_test/utils.js"; +import { mockErc20ABI } from "../generated.js"; +import type { PanopticPool } from "../types/PanopticPool.js"; +import type { PanopticPosition } from "../types/PanopticPosition.js"; +import { createPanopticPosition } from "../utils/createPanopticPosition.js"; +import { getPanoptionLegData } from "./getPanoptionLegData.js"; +import { simulatePanopticSFPMInitializeAMMPool } from "./simulatePanopticSFPMInitializeAMMPool.js"; +import { simulatePanopticSFPMMintTokenizedPosition } from "./simulatePanopticSFPMMintTokenizedPosition.js"; + +let id: Hex | undefined = undefined; + +let pool: PanopticPool; +let position: PanopticPosition; + +beforeEach(async () => { + if (id === undefined) { + pool = await deployPool(); + const { request: initializeRequest } = + await simulatePanopticSFPMInitializeAMMPool(publicClient, { + args: { + pool: pool.uniswapPool, + sfpm: pool.factory.semiFungiblePositionManager, + }, + }); + + const initializeHash = await walletClient.writeContract(initializeRequest); + await publicClient.waitForTransactionReceipt({ hash: initializeHash }); + + const { request: approveRequest } = await simulateContract(publicClient, { + address: pool.collateralTracker0.underlyingToken.address, + abi: mockErc20ABI, + functionName: "approve", + args: [pool.factory.semiFungiblePositionManager.address, 10n ** 18n], + account: ALICE, + }); + + const approveHash = await writeContract(walletClient, approveRequest); + await publicClient.waitForTransactionReceipt({ hash: approveHash }); + + position = createPanopticPosition( + ALICE, + pool, + [ + { + asset: "token0", + optionRatio: 1, + position: "short", + tokenType: "token0", + riskPartnerIndex: 0, + tickLower: createUniswapV3Tick(0), + tickUpper: createUniswapV3Tick(10), + }, + undefined, + undefined, + undefined, + ], + sepolia.id, + ); + + const { request } = await simulatePanopticSFPMMintTokenizedPosition( + publicClient, + { + args: { + position, + amount: 10n ** 18n, + }, + account: ALICE, + }, + ); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); + } else { + await testClient.revert({ id }); + } + id = await testClient.snapshot(); +}, 100_000); + +test("get leg data", async () => { + const legData = await getPanoptionLegData(publicClient, { + leg: position.legs[0]!, + address: ALICE, + pool: pool, + tick: createUniswapV3Tick(0), + }); + + expect(legData.liquidityAdded).toBe(2n ** 128n - 1n); +});