-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
299 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/panoptic-sdk/src/publicActions/getPanopticCollateralData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { createAmountFromString } from "reverse-mirage"; | ||
import { type Hex } from "viem"; | ||
import { simulateContract, writeContract } from "viem/actions"; | ||
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/index.js"; | ||
import { getPanopticCollateralData } from "./getPanopticCollateralData.js"; | ||
import { simulatePanopticCollateralDeposit } from "./simulatePanopticCollateralDeposit.js"; | ||
|
||
let id: Hex | undefined = undefined; | ||
|
||
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 writeContract(walletClient, depositRequest); | ||
await publicClient.waitForTransactionReceipt({ hash: depositHash }); | ||
} else { | ||
await testClient.revert({ id }); | ||
} | ||
id = await testClient.snapshot(); | ||
}, 100_000); | ||
|
||
test("get collateral data", async () => { | ||
const collateralData = await getPanopticCollateralData(publicClient, { | ||
panopticCollateral: pool.collateralTracker0, | ||
}); | ||
|
||
expect(collateralData.collateral).toStrictEqual(pool.collateralTracker0); | ||
expect(collateralData.totalSupply).toStrictEqual( | ||
createAmountFromString(pool.collateralTracker0, ".999"), | ||
); | ||
expect(collateralData.poolAssets).toStrictEqual( | ||
createAmountFromString(pool.collateralTracker0.underlyingToken, "1"), | ||
); | ||
}); |
71 changes: 71 additions & 0 deletions
71
packages/panoptic-sdk/src/publicActions/getPanopticCollateralPositionData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { createAmountFromString } from "reverse-mirage"; | ||
import { type Hex } from "viem"; | ||
import { simulateContract, writeContract } from "viem/actions"; | ||
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/index.js"; | ||
import { getPanopticCollateralPositionData } from "./getPanopticCollateralPositionData.js"; | ||
import { simulatePanopticCollateralDeposit } from "./simulatePanopticCollateralDeposit.js"; | ||
|
||
let id: Hex | undefined = undefined; | ||
|
||
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 writeContract(walletClient, depositRequest); | ||
await publicClient.waitForTransactionReceipt({ hash: depositHash }); | ||
} else { | ||
await testClient.revert({ id }); | ||
} | ||
id = await testClient.snapshot(); | ||
}, 100_000); | ||
|
||
test("get collateral data", async () => { | ||
const collateralPosition = await getPanopticCollateralPositionData( | ||
publicClient, | ||
{ | ||
panopticCollateral: pool.collateralTracker0, | ||
address: ALICE, | ||
}, | ||
); | ||
|
||
expect(collateralPosition.token).toStrictEqual(pool.collateralTracker0); | ||
expect(collateralPosition.amount).toStrictEqual( | ||
createAmountFromString(pool.collateralTracker0, ".999").amount, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.