Skip to content

Commit

Permalink
panoptic update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Sep 25, 2023
1 parent be4f33c commit 05ae0a8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 268 deletions.
4 changes: 2 additions & 2 deletions packages/panoptic-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"@biomejs/biome": "^1.2.2",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"viem": "^1.12.1"
"viem": "^1.12.2"
},
"dependencies": {
"reverse-mirage": "1.0.0-next.1",
"reverse-mirage": "1.0.0-next.2",
"tiny-invariant": "^1.3.1",
"uniswap-v3-sdk": "workspace:*"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ReverseMirage, createAmountFromRaw } from "reverse-mirage";
import { createAmountFromRaw } from "reverse-mirage";
import type { Chain, Client, ReadContractParameters, Transport } from "viem";
import { readContract } from "viem/actions";
import { collateralTrackerABI } from "../generated.js";
Expand All @@ -16,72 +16,30 @@ export type GetPanopticCollateralDataParameters = Omit<

export type GetPanopticCollateralDataReturnType = PanopticCollateralData;

export const getPanopticCollateralData = <
TChain extends Chain | undefined,
T extends "select" | undefined,
>(
export const getPanopticCollateralData = <TChain extends Chain | undefined,>(
client: Client<Transport, TChain>,
{ panopticCollateral, ...request }: GetPanopticCollateralDataParameters,
type?: T,
) =>
(type === undefined
? Promise.all([
readContract(client, {
abi: collateralTrackerABI,
functionName: "totalSupply",
address: panopticCollateral.address,
...request,
}),
readContract(client, {
abi: collateralTrackerABI,
functionName: "getPoolData",
address: panopticCollateral.address,
...request,
}),
]).then(([totalSupply, poolData]) => ({
type: "panopticCollateralData",
collateral: panopticCollateral,
totalSupply: createAmountFromRaw(panopticCollateral, totalSupply),
poolAssets: createAmountFromRaw(
panopticCollateral.underlyingToken,
poolData[0],
),
inAmm: createAmountFromRaw(
panopticCollateral.underlyingToken,
poolData[1],
),
}))
: {
read: () =>
Promise.all([
readContract(client, {
abi: collateralTrackerABI,
functionName: "totalSupply",
address: panopticCollateral.address,
...request,
}),
readContract(client, {
abi: collateralTrackerABI,
functionName: "getPoolData",
address: panopticCollateral.address,
...request,
}),
]),
parse: ([totalSupply, poolData]) => ({
type: "panopticCollateralData",
collateral: panopticCollateral,
totalSupply: createAmountFromRaw(panopticCollateral, totalSupply),
poolAssets: createAmountFromRaw(
panopticCollateral.underlyingToken,
poolData[0],
),
inAmm: createAmountFromRaw(
panopticCollateral.underlyingToken,
poolData[1],
),
}),
}) as ReverseMirage<
[bigint, [bigint, bigint, bigint]],
GetPanopticCollateralDataReturnType,
T
>;
): Promise<GetPanopticCollateralDataReturnType> =>
Promise.all([
readContract(client, {
abi: collateralTrackerABI,
functionName: "totalSupply",
address: panopticCollateral.address,
...request,
}),
readContract(client, {
abi: collateralTrackerABI,
functionName: "getPoolData",
address: panopticCollateral.address,
...request,
}),
]).then(([totalSupply, poolData]) => ({
type: "panopticCollateralData",
collateral: panopticCollateral,
totalSupply: createAmountFromRaw(panopticCollateral, totalSupply),
poolAssets: createAmountFromRaw(
panopticCollateral.underlyingToken,
poolData[0],
),
inAmm: createAmountFromRaw(panopticCollateral.underlyingToken, poolData[1]),
}));
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ReverseMirage, getERC20BalanceOf } from "reverse-mirage";
import { getERC20BalanceOf } from "reverse-mirage";
import type {
Address,
Chain,
Expand All @@ -25,45 +25,16 @@ export type GetPanopticCollateralPositionDataReturnType =

export const getPanopticCollateralPositionData = <
TChain extends Chain | undefined,
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
{
panopticCollateral,
address,
...request
}: GetPanopticCollateralPositionDataParameters,
type?: T,
) =>
(type === undefined
? getERC20BalanceOf(client, {
erc20: panopticCollateral,
address,
...request,
})
: {
read: () =>
getERC20BalanceOf(
client,
{
erc20: panopticCollateral,
address,
...request,
},
"select",
).read(),
parse: (data) =>
getERC20BalanceOf(
client,
{
erc20: panopticCollateral,
address,
...request,
},
"select",
).parse(data),
}) as ReverseMirage<
bigint,
GetPanopticCollateralPositionDataReturnType,
T
>;
): Promise<GetPanopticCollateralPositionDataReturnType> =>
getERC20BalanceOf(client, {
erc20: panopticCollateral,
address,
...request,
});
143 changes: 22 additions & 121 deletions packages/panoptic-sdk/src/publicActions/getPanopticPoolData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type ReverseMirage } from "reverse-mirage";
import { getUniswapV3PoolData } from "uniswap-v3-sdk";
import type { Chain, Client, ReadContractParameters, Transport } from "viem";
import { collateralTrackerABI } from "../generated.js";
Expand All @@ -14,125 +13,27 @@ export type GetPanopticPoolDataParameters = Omit<

export type GetPanopticPoolDataReturnType = PanopticPoolData;

export const getPanopticPoolData = <
TChain extends Chain | undefined,
T extends "select" | undefined,
>(
export const getPanopticPoolData = <TChain extends Chain | undefined,>(
client: Client<Transport, TChain>,
{ panopticPool, ...request }: GetPanopticPoolDataParameters,
type?: T,
) =>
(type === undefined
? Promise.all([
getUniswapV3PoolData(client, {
pool: panopticPool.uniswapPool,
...request,
}),
getPanopticCollateralData(client, {
panopticCollateral: panopticPool.collateralTracker0,
...request,
}),
getPanopticCollateralData(client, {
panopticCollateral: panopticPool.collateralTracker1,
...request,
}),
]).then(([poolData, collateral0Data, collateral1Data]) => ({
type: "panopticPoolData",
panopticPool,
collateralTracker0Data: collateral0Data,
collateralTracker1Data: collateral1Data,
uniswapPoolData: poolData,
}))
: {
read: () =>
Promise.all([
getUniswapV3PoolData(
client,
{
pool: panopticPool.uniswapPool,
...request,
},
"select",
).read(),
getPanopticCollateralData(
client,
{
panopticCollateral: panopticPool.collateralTracker0,
...request,
},
"select",
).read(),
getPanopticCollateralData(
client,
{
panopticCollateral: panopticPool.collateralTracker1,
...request,
},
"select",
).read(),
]),
parse: (data) => ({
type: "panopticPoolData",
uniswapPoolData: getUniswapV3PoolData(
client,
{
pool: panopticPool.uniswapPool,
...request,
},
"select",
).parse(data[0]),
collateralTracker0Data: getPanopticCollateralData(
client,
{
panopticCollateral: panopticPool.collateralTracker0,
...request,
},
"select",
).parse(data[1]),
collateralTracker1Data: getPanopticCollateralData(
client,
{
panopticCollateral: panopticPool.collateralTracker1,
...request,
},
"select",
).parse(data[1]),
}),
}) as ReverseMirage<
[
readonly [
{
poolData: readonly [
bigint,
number,
number,
number,
number,
number,
boolean,
];
tickData: readonly [
readonly [
bigint,
bigint,
bigint,
bigint,
bigint,
bigint,
number,
boolean,
],
bigint,
];
},
bigint,
bigint,
bigint,
readonly [bigint, bigint],
],
[bigint, [bigint, bigint, bigint]],
[bigint, [bigint, bigint, bigint]],
],
GetPanopticPoolDataReturnType,
T
>;
): Promise<GetPanopticPoolDataReturnType> =>
Promise.all([
getUniswapV3PoolData(client, {
pool: panopticPool.uniswapPool,
...request,
}),
getPanopticCollateralData(client, {
panopticCollateral: panopticPool.collateralTracker0,
...request,
}),
getPanopticCollateralData(client, {
panopticCollateral: panopticPool.collateralTracker1,
...request,
}),
]).then(([poolData, collateral0Data, collateral1Data]) => ({
type: "panopticPoolData",
panopticPool,
collateralTracker0Data: collateral0Data,
collateralTracker1Data: collateral1Data,
uniswapPoolData: poolData,
}));
Loading

0 comments on commit 05ae0a8

Please sign in to comment.