diff --git a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.test.ts b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.test.ts index 5166441..5a66cbc 100644 --- a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.test.ts +++ b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.test.ts @@ -1,7 +1,17 @@ +import { createAmountFromString } from "reverse-mirage"; import { type Hex } from "viem"; +import { simulateContract, writeContract } from "viem/actions"; import { beforeEach, test } from "vitest"; -import { deployPool, testClient } from "../../_test/utils.js"; +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/index.js"; +import { simulatePanopticCollateralDeposit } from "./simulatePanopticCollateralDeposit.js"; let id: Hex | undefined = undefined; @@ -10,20 +20,35 @@ let pool: PanopticPool; beforeEach(async () => { if (id === undefined) { pool = await deployPool(); + + const { request: approveRequest } = await simulateContract(publicClient, { + address: pool.collateralTracker0.underlyingToken.address, + abi: mockErc20ABI, + functionName: "approve", + args: [pool.collateralTracker0.address, 10n ** 18n], + account: ALICE, + }); + + const approveHash = await writeContract(walletClient, approveRequest); + await publicClient.waitForTransactionReceipt({ hash: approveHash }); } else { await testClient.revert({ id }); } id = await testClient.snapshot(); }, 100_000); -test.skip("deposit", async () => { - // const { request } = await simulatePanopticCollateralDeposit(publicClient, { - // args: { - // amount: createAmountFromString(collat.underlyingToken, "0.5"), - // to: ALICE, - // }, - // account: ALICE, - // }); - // const hash = await walletClient.writeContract(request); - // await publicClient.waitForTransactionReceipt({ hash }); +test("simulate collateral deposit", async () => { + const { request } = await simulatePanopticCollateralDeposit(publicClient, { + args: { + collateral: pool.collateralTracker0, + amount: createAmountFromString( + pool.collateralTracker0.underlyingToken, + "0.5", + ), + to: ALICE, + }, + account: ALICE, + }); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); }); diff --git a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.ts b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.ts index 035590d..1047b74 100644 --- a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.ts +++ b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralDeposit.ts @@ -14,6 +14,7 @@ import type { PanopticCollateral } from "../../types/PanopticCollateral.js"; export type PanopticCollateralDepositParameters< TPanopticCollateral extends PanopticCollateral, > = { + collateral: TPanopticCollateral; amount: ERC20Amount; to: Address; }; @@ -49,7 +50,7 @@ export const simulatePanopticCollateralDeposit = < >( client: Client, { - args: { amount, to }, + args: { collateral, amount, to }, ...request }: SimulatePanopticCollateralDepositParameters< TPanopticCollateral, @@ -60,7 +61,7 @@ export const simulatePanopticCollateralDeposit = < SimulatePanopticCollateralDepositReturnType > => simulateContract(client, { - address: amount.token.address, + address: collateral.address, abi: collateralTrackerABI, functionName: "deposit", args: [amount.amount, to], diff --git a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralMint.test.ts b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralMint.test.ts index 33a377e..88b76fd 100644 --- a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralMint.test.ts +++ b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralMint.test.ts @@ -1,7 +1,19 @@ +import { createAmountFromString } from "reverse-mirage"; import { type Hex } from "viem"; +import { simulateContract, writeContract } from "viem/actions"; import { beforeEach, test } from "vitest"; -import { deployPool, testClient } from "../../_test/utils.js"; -import type { PanopticPool } from "../../index.js"; +import { ALICE } from "../../_test/constants.js"; +import { + deployPool, + publicClient, + testClient, + walletClient, +} from "../../_test/utils.js"; +import { mockErc20ABI } from "../../generated.js"; +import { + type PanopticPool, + simulatePanopticCollateralMint, +} from "../../index.js"; let id: Hex | undefined = undefined; @@ -10,20 +22,30 @@ let pool: PanopticPool; beforeEach(async () => { if (id === undefined) { pool = await deployPool(); + const { request: approveRequest } = await simulateContract(publicClient, { + address: pool.collateralTracker0.underlyingToken.address, + abi: mockErc20ABI, + functionName: "approve", + args: [pool.collateralTracker0.address, 10n ** 18n], + account: ALICE, + }); + + const approveHash = await writeContract(walletClient, approveRequest); + await publicClient.waitForTransactionReceipt({ hash: approveHash }); } else { await testClient.revert({ id }); } id = await testClient.snapshot(); }, 100_000); -test.skip("Mint", async () => { - // const { request } = await simulatePanopticCollateralMint(publicClient, { - // args: { - // amount: createAmountFromString(collat, "0.5"), - // to: ALICE, - // }, - // account: ALICE, - // }); - // const hash = await walletClient.writeContract(request); - // await publicClient.waitForTransactionReceipt({ hash }); +test("simulate collateral mint", async () => { + const { request } = await simulatePanopticCollateralMint(publicClient, { + args: { + amount: createAmountFromString(pool.collateralTracker0, "0.5"), + to: ALICE, + }, + account: ALICE, + }); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); }); diff --git a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralRedeem.test.ts b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralRedeem.test.ts index 68c3023..7f25238 100644 --- a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralRedeem.test.ts +++ b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralRedeem.test.ts @@ -1,7 +1,20 @@ +import { createAmountFromString } from "reverse-mirage"; import { type Hex } from "viem"; +import { simulateContract, writeContract } from "viem/actions"; import { beforeEach, test } from "vitest"; -import { deployPool, testClient } from "../../_test/utils.js"; -import type { PanopticPool } from "../../index.js"; +import { ALICE } from "../../_test/constants.js"; +import { + deployPool, + publicClient, + testClient, + walletClient, +} from "../../_test/utils.js"; +import { mockErc20ABI } from "../../generated.js"; +import { + type PanopticPool, + simulatePanopticCollateralDeposit, + simulatePanopticCollateralRedeem, +} from "../../index.js"; let id: Hex | undefined = undefined; @@ -10,20 +23,49 @@ let pool: PanopticPool; beforeEach(async () => { if (id === undefined) { pool = await deployPool(); + + const { request: approveRequest } = await simulateContract(publicClient, { + address: pool.collateralTracker0.underlyingToken.address, + abi: mockErc20ABI, + functionName: "approve", + args: [pool.collateralTracker0.address, 10n ** 18n], + account: ALICE, + }); + + const approveHash = await writeContract(walletClient, approveRequest); + await publicClient.waitForTransactionReceipt({ hash: approveHash }); + + const { request: depositRequest } = await simulatePanopticCollateralDeposit( + publicClient, + { + args: { + collateral: pool.collateralTracker0, + amount: createAmountFromString( + pool.collateralTracker0.underlyingToken, + "1", + ), + to: ALICE, + }, + account: ALICE, + }, + ); + const depositHash = await walletClient.writeContract(depositRequest); + await publicClient.waitForTransactionReceipt({ hash: depositHash }); } else { await testClient.revert({ id }); } id = await testClient.snapshot(); }, 100_000); -test.skip("Redeem", async () => { - // const { request } = await simulatePanopticCollateralRedeem(walletClient, { - // args: { - // amount: createAmountFromString(collat, "0.5"), - // from: ALICE, - // to: ALICE, - // }, - // }); - // const hash = await walletClient.writeContract(request); - // await publicClient.waitForTransactionReceipt({ hash }); +test("simulate collateral redeem", async () => { + const { request } = await simulatePanopticCollateralRedeem(publicClient, { + args: { + amount: createAmountFromString(pool.collateralTracker0, "0.5"), + from: ALICE, + to: ALICE, + }, + account: ALICE, + }); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); }); diff --git a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.test.ts b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.test.ts index 5673881..4094bf0 100644 --- a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.test.ts +++ b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.test.ts @@ -1,7 +1,20 @@ +import { createAmountFromString } from "reverse-mirage"; import { type Hex } from "viem"; +import { simulateContract, writeContract } from "viem/actions"; import { beforeEach, test } from "vitest"; -import { deployPool, testClient } from "../../_test/utils.js"; -import type { PanopticPool } from "../../index.js"; +import { ALICE } from "../../_test/constants.js"; +import { + deployPool, + publicClient, + testClient, + walletClient, +} from "../../_test/utils.js"; +import { mockErc20ABI } from "../../generated.js"; +import { + type PanopticPool, + simulatePanopticCollateralDeposit, + simulatePanopticCollateralWithdraw, +} from "../../index.js"; let id: Hex | undefined = undefined; @@ -10,21 +23,53 @@ let pool: PanopticPool; beforeEach(async () => { if (id === undefined) { pool = await deployPool(); + + const { request: approveRequest } = await simulateContract(publicClient, { + address: pool.collateralTracker0.underlyingToken.address, + abi: mockErc20ABI, + functionName: "approve", + args: [pool.collateralTracker0.address, 10n ** 18n], + account: ALICE, + }); + + const approveHash = await writeContract(walletClient, approveRequest); + await publicClient.waitForTransactionReceipt({ hash: approveHash }); + + const { request: depositRequest } = await simulatePanopticCollateralDeposit( + publicClient, + { + args: { + collateral: pool.collateralTracker0, + amount: createAmountFromString( + pool.collateralTracker0.underlyingToken, + "0.5", + ), + to: ALICE, + }, + account: ALICE, + }, + ); + const depositHash = await walletClient.writeContract(depositRequest); + await publicClient.waitForTransactionReceipt({ hash: depositHash }); } else { await testClient.revert({ id }); } id = await testClient.snapshot(); }, 100_000); -test.skip("WithsimulatePanopticCollateralWithdraw", async () => { - // const { request } = await simulatePanopticCollateralWithdraw(publicClient, { - // args: { - // amount: createAmountFromString(collat.underlyingToken, "0.5"), - // from: ALICE, - // to: ALICE, - // }, - // account: ALICE, - // }); - // const hash = await walletClient.writeContract(request); - // await publicClient.waitForTransactionReceipt({ hash }); +test("simulate collateral withdraw", async () => { + const { request } = await simulatePanopticCollateralWithdraw(publicClient, { + args: { + collateral: pool.collateralTracker0, + amount: createAmountFromString( + pool.collateralTracker0.underlyingToken, + "0.5", + ), + from: ALICE, + to: ALICE, + }, + account: ALICE, + }); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); }); diff --git a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.ts b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.ts index 912c3fa..e4aa54f 100644 --- a/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.ts +++ b/packages/panoptic-sdk/src/publicActions/collateralTracker/simulatePanopticCollateralWithdraw.ts @@ -14,6 +14,7 @@ import type { PanopticCollateral } from "../../types/PanopticCollateral.js"; export type PanopticCollateralWithdrawParameters< TPanopticCollateral extends PanopticCollateral, > = { + collateral: TPanopticCollateral; amount: ERC20Amount; from: Address; to: Address; @@ -50,7 +51,7 @@ export const simulatePanopticCollateralWithdraw = < >( client: Client, { - args: { amount, to, from }, + args: { collateral, amount, to, from }, ...request }: SimulatePanopticCollateralWithdrawParameters< TPanopticCollateral, @@ -61,7 +62,7 @@ export const simulatePanopticCollateralWithdraw = < SimulatePanopticCollateralWithdrawReturnType > => simulateContract(client, { - address: amount.token.address, + address: collateral.address, abi: collateralTrackerABI, functionName: "withdraw", args: [amount.amount, from, to],