-
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
8 changed files
with
237 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { Chain, Client, Transport } from "viem"; | ||
import { | ||
type GetPanopticCollateralDataParameters, | ||
getPanopticCollateralData, | ||
} from "../publicActions/getPanopticCollateralData.js"; | ||
import { | ||
type GetPanopticCollateralPositionDataParameters, | ||
getPanopticCollateralPositionData, | ||
} from "../publicActions/getPanopticCollateralPositionData.js"; | ||
import { | ||
type GetPanopticPoolDataParameters, | ||
getPanopticPoolData, | ||
} from "../publicActions/getPanopticPoolData.js"; | ||
import { | ||
type GetPanopticPositionDataParameters, | ||
getPanopticPositionData, | ||
} from "../publicActions/getPanopticPositionData.js"; | ||
|
||
export const publicActionPanoptic = < | ||
TChain extends Chain | undefined = Chain | undefined, | ||
>( | ||
client: Client<Transport, TChain>, | ||
) => ({ | ||
getPanopticCollateralData: (args: GetPanopticCollateralDataParameters) => | ||
getPanopticCollateralData(client, args), | ||
|
||
getPanopticCollateralPositionData: ( | ||
args: GetPanopticCollateralPositionDataParameters, | ||
) => getPanopticCollateralPositionData(client, args), | ||
|
||
getPanopticPoolData: (args: GetPanopticPoolDataParameters) => | ||
getPanopticPoolData(client, args), | ||
|
||
getPanopticPositionData: (args: GetPanopticPositionDataParameters) => | ||
getPanopticPositionData(client, args), | ||
}); |
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,26 @@ | ||
export type { | ||
PanopticCollateral, | ||
PanopticCollateralData, | ||
PanopticCollateralParamters, | ||
PanopticCollateralPositionData, | ||
PanopticFactory, | ||
PanopticPool, | ||
PanopticPoolData, | ||
PanopticPosition, | ||
PanopticPositionData, | ||
PanopticSemiFungiblePositionManager, | ||
} from "./types/index.js"; | ||
|
||
export { getPanopticCollateralData } from "./publicActions/getPanopticCollateralData.js"; | ||
export { getPanopticCollateralPositionData } from "./publicActions/getPanopticCollateralPositionData.js"; | ||
export { getPanopticPoolData } from "./publicActions/getPanopticPoolData.js"; | ||
export { getPanopticPositionData } from "./publicActions/getPanopticPositionData.js"; | ||
|
||
export { publicActionPanoptic } from "./decorator/publicActions.js"; | ||
|
||
export { | ||
semiFungiblePositionManagerABI, | ||
panopticFactoryABI, | ||
panopticPoolABI, | ||
collateralTrackerABI, | ||
} from "./generated.js"; |
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,77 @@ | ||
import { createFraction } from "reverse-mirage"; | ||
import type { UniswapV3Tick } from "uniswap-v3-sdk"; | ||
import type { Chain, Client, ReadContractParameters, Transport } from "viem"; | ||
import { readContract } from "viem/actions"; | ||
import { panopticPoolABI } from "../generated.js"; | ||
import type { | ||
PanopticPosition, | ||
PanopticPositionData, | ||
} from "../types/PanopticPosition.js"; | ||
import { getPanoptionLegData } from "./getPanoptionLegData.js"; | ||
|
||
export type GetPanopticPositionDataParameters = Omit< | ||
ReadContractParameters<typeof panopticPoolABI, "totalSupply">, | ||
"address" | "abi" | "functionName" | "args" | ||
> & { | ||
panopticPosition: PanopticPosition; | ||
tick: UniswapV3Tick; | ||
}; | ||
|
||
export type GetPanopticPositionDataReturnType = PanopticPositionData; | ||
|
||
export const getPanopticPositionData = <TChain extends Chain | undefined>( | ||
client: Client<Transport, TChain>, | ||
{ panopticPosition, tick, ...request }: GetPanopticPositionDataParameters, | ||
): Promise<GetPanopticPositionDataReturnType> => | ||
Promise.all([ | ||
readContract(client, { | ||
abi: panopticPoolABI, | ||
functionName: "optionPositionBalance", | ||
address: panopticPosition.pool.address, | ||
args: [panopticPosition.address, panopticPosition.id], | ||
...request, | ||
}), | ||
panopticPosition.legs[0] | ||
? getPanoptionLegData(client, { | ||
leg: panopticPosition.legs[0], | ||
address: panopticPosition.address, | ||
pool: panopticPosition.pool, | ||
tick, | ||
...request, | ||
}) | ||
: undefined, | ||
panopticPosition.legs[1] | ||
? getPanoptionLegData(client, { | ||
leg: panopticPosition.legs[1], | ||
address: panopticPosition.address, | ||
pool: panopticPosition.pool, | ||
tick, | ||
...request, | ||
}) | ||
: undefined, | ||
panopticPosition.legs[2] | ||
? getPanoptionLegData(client, { | ||
leg: panopticPosition.legs[2], | ||
address: panopticPosition.address, | ||
pool: panopticPosition.pool, | ||
tick, | ||
...request, | ||
}) | ||
: undefined, | ||
panopticPosition.legs[3] | ||
? getPanoptionLegData(client, { | ||
leg: panopticPosition.legs[3], | ||
address: panopticPosition.address, | ||
pool: panopticPosition.pool, | ||
tick, | ||
...request, | ||
}) | ||
: undefined, | ||
] as const).then(([optionsBalance, leg0, leg1, leg2, leg3]) => ({ | ||
type: "panopticPositionData", | ||
amount: optionsBalance[0], | ||
token0Utilization: createFraction(optionsBalance[1], 2n ** 64n), | ||
token1Utilization: createFraction(optionsBalance[2], 2n ** 64n), | ||
token: panopticPosition, | ||
legData: [leg0, leg1, leg2, leg3], | ||
})); |
86 changes: 86 additions & 0 deletions
86
packages/panoptic-sdk/src/publicActions/getPanoptionLegData.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,86 @@ | ||
import type { UniswapV3Tick } from "uniswap-v3-sdk"; | ||
import type { | ||
Address, | ||
Chain, | ||
Client, | ||
ReadContractParameters, | ||
Transport, | ||
} from "viem"; | ||
import { readContract } from "viem/actions"; | ||
import { | ||
panopticPoolABI, | ||
semiFungiblePositionManagerABI, | ||
} from "../generated.js"; | ||
import type { PanopticPool } from "../types/PanopticPool.js"; | ||
import type { | ||
PanoptionLeg, | ||
PanoptionLegData, | ||
} from "../types/PanopticPosition.js"; | ||
import type {} from "./getPanopticPositionData.js"; | ||
|
||
export type GetPanoptionLegDataParameters = Omit< | ||
ReadContractParameters<typeof panopticPoolABI, "totalSupply">, | ||
"address" | "abi" | "functionName" | "args" | ||
> & { | ||
leg: PanoptionLeg; | ||
address: Address; | ||
pool: PanopticPool; | ||
tick: UniswapV3Tick; | ||
}; | ||
|
||
export type GetPanoptionLegDataReturnType = PanoptionLegData; | ||
|
||
export const getPanoptionLegData = <TChain extends Chain | undefined>( | ||
client: Client<Transport, TChain>, | ||
{ leg, pool, address, tick, ...request }: GetPanoptionLegDataParameters, | ||
): Promise<GetPanoptionLegDataReturnType> => | ||
Promise.all([ | ||
readContract(client, { | ||
abi: semiFungiblePositionManagerABI, | ||
functionName: "getAccountLiquidity", | ||
address: pool.factory.semiFungiblePositionManager.address, | ||
args: [ | ||
pool.uniswapPool.address, | ||
address, | ||
leg.tokenType === "token0" ? 0n : 1n, | ||
leg.tickLower.tick, | ||
leg.tickUpper.tick, | ||
], | ||
...request, | ||
}), | ||
readContract(client, { | ||
abi: semiFungiblePositionManagerABI, | ||
functionName: "getAccountPremium", | ||
address: pool.factory.semiFungiblePositionManager.address, | ||
args: [ | ||
pool.uniswapPool.address, | ||
address, | ||
leg.tokenType === "token0" ? 0n : 1n, | ||
leg.tickLower.tick, | ||
leg.tickUpper.tick, | ||
tick.tick, | ||
leg.position === "short" ? 0n : 1n, | ||
], | ||
...request, | ||
}), | ||
readContract(client, { | ||
abi: semiFungiblePositionManagerABI, | ||
functionName: "getAccountFeesBase", | ||
address: pool.factory.semiFungiblePositionManager.address, | ||
args: [ | ||
pool.uniswapPool.address, | ||
address, | ||
leg.tokenType === "token0" ? 0n : 1n, | ||
leg.tickLower.tick, | ||
leg.tickUpper.tick, | ||
], | ||
...request, | ||
}), | ||
] as const).then(([legLiquidity, legPremium, legFeesBase]) => ({ | ||
liquidityAdded: legLiquidity && 2n ** 128n - 1n, | ||
liquidityRemoved: legLiquidity >> 128n, | ||
accountPremium0: legPremium[0], | ||
accountPremium1: legPremium[1], | ||
baseFee0: legFeesBase[0], | ||
baseFee1: legFeesBase[1], | ||
})); |
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import type { WETH } from "reverse-mirage"; | ||
import type { UniswapV3Factory } from "uniswap-v3-sdk"; | ||
import type { Address } from "viem/accounts"; | ||
import type { PanopticSemiFungiblePositionManager } from "./PanopticSemiFungiblePositionManager.js"; | ||
|
||
export type PanopticFactory = { | ||
type: "panopticFactory"; | ||
address: Address; | ||
owner: Address; | ||
uniswapFactory: UniswapV3Factory; | ||
semiFungiblePositionManager: PanopticSemiFungiblePositionManager; | ||
weth: WETH; | ||
blockCreated: bigint; | ||
}; |
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