Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition panopticPool contract address to be variable #32

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/connectors/panoptic/panoptic.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ export async function queryGreeks(
req: GreekQueryRequest
): Promise<GreekQueryResponse | Error> {
const { wallet } = await txWriteData(ethereumish, req.address);
const result = await panopticish.queryGreeks(wallet, req.tick, req.positionIdList, req.greek);
const result = await panopticish.queryGreeks(
wallet,
req.panopticPool,
req.tick,
req.positionIdList,
req.greek
);

if (result instanceof Error) {
logger.error(`Error executing queryGreeks: ${result.message}`);
Expand Down Expand Up @@ -759,6 +765,7 @@ export async function calculateAccumulatedFeesBatch(
const { wallet } = await txWriteData(ethereumish, req.address);
const result = await panopticish.calculateAccumulatedFeesBatch(
wallet,
req.panopticPool,
req.includePendingPremium,
req.positionIdList
);
Expand All @@ -781,7 +788,10 @@ export async function getCollateralToken0(
req: CollateralTokenRequest
): Promise<CollateralTokenResponse | Error> {
const { wallet } = await txWriteData(ethereumish, req.address);
const result = await panopticish.collateralToken0(wallet);
const result = await panopticish.collateralToken0(
wallet,
req.panopticPool
);

if (result instanceof Error) {
logger.error(`Error executing collateralToken0: ${result.message}`);
Expand All @@ -799,7 +809,10 @@ export async function getCollateralToken1(
req: CollateralTokenRequest
): Promise<CollateralTokenResponse | Error> {
const { wallet } = await txWriteData(ethereumish, req.address);
const result = await panopticish.collateralToken1(wallet);
const result = await panopticish.collateralToken1(
wallet,
req.panopticPool
);

if (result instanceof Error) {
logger.error(`Error executing collateralToken1: ${result.message}`);
Expand All @@ -822,6 +835,7 @@ export async function burn(
const gasPrice: number = ethereumish.gasPrice;
const tx: ContractReceipt | Error = await panopticish.executeBurn(
wallet,
req.panopticPool,
req.burnTokenId,
req.newPositionIdList,
req.tickLimitLow,
Expand Down Expand Up @@ -870,6 +884,7 @@ export async function forceExercise(
const gasPrice: number = ethereumish.gasPrice;
const tx: ContractReceipt | Error = await panopticish.forceExercise(
wallet,
req.panopticPool,
req.touchedId,
req.positionIdListExercisee,
req.positionIdListExercisor,
Expand Down Expand Up @@ -917,6 +932,7 @@ export async function liquidate(
const gasPrice: number = ethereumish.gasPrice;
const tx: ContractReceipt | Error = await panopticish.liquidate(
wallet,
req.panopticPool,
req.positionIdListLiquidator,
req.liquidatee,
req.delegations,
Expand Down Expand Up @@ -965,6 +981,7 @@ export async function mint(
const gasPrice: number = ethereumish.gasPrice;
const tx: ContractReceipt | Error = await panopticish.executeMint(
wallet,
req.panopticPool,
req.positionIdList,
BigNumber.from(req.positionSize),
req.effectiveLiquidityLimit,
Expand Down Expand Up @@ -1008,7 +1025,8 @@ export async function numberOfPositions(
): Promise<NumberOfPositionsResponse | Error> {
const { wallet } = await txWriteData(ethereumish, req.address);
const result = await panopticish.numberOfPositions(
wallet
wallet,
req.panopticPool
);

if (result instanceof Error) {
Expand All @@ -1029,6 +1047,7 @@ export async function optionPositionBalance(
const { wallet } = await txWriteData(ethereumish, req.address);
const result = await panopticish.optionPositionBalance(
wallet,
req.panopticPool,
req.tokenId
);

Expand All @@ -1053,7 +1072,10 @@ export async function pokeMedian(
try {
const { wallet } = await txWriteData(ethereumish, req.address);
const gasPrice: number = ethereumish.gasPrice;
const tx: ContractReceipt | Error = await panopticish.pokeMedian(wallet);
const tx: ContractReceipt | Error = await panopticish.pokeMedian(
wallet,
req.panopticPool
);

if (tx instanceof Error) {
logger.error(`Error executing pokeMedian: ${tx.message}`);
Expand Down Expand Up @@ -1097,6 +1119,7 @@ export async function settleLongPremium(
const gasPrice: number = ethereumish.gasPrice;
const tx: ContractReceipt | Error = await panopticish.settleLongPremium(
wallet,
req.panopticPool,
req.positionIdList,
req.owner,
req.legIndex
Expand Down
62 changes: 29 additions & 33 deletions src/connectors/panoptic/panoptic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class Panoptic {
private _PanopticFactory: string;
private _PanopticHelper: string;
private _UniswapMigrator: string;
private _PanopticPool: string;
private _TokenIdLibrary: string;
private _absoluteGasLimit: number;
private _gasLimitCushionFactor: number;
Expand All @@ -55,7 +54,6 @@ export class Panoptic {
this._PanopticFactory = config.PanopticFactory(chain, network);
this._PanopticHelper = config.PanopticHelper(chain, network);
this._UniswapMigrator = config.UniswapMigrator(chain, network);
this._PanopticPool = config.PanopticPool(chain, network);
this._TokenIdLibrary = config.TokenIdLibrary(chain, network);
this._ttl = config.ttl;
this._subgraphUrl = config.subgraphUrl;
Expand Down Expand Up @@ -135,9 +133,6 @@ export class Panoptic {
public get UniswapMigrator(): string {
return this._UniswapMigrator;
}
public get PanopticPool(): string {
return this._PanopticPool;
}
public get TokenIdLibrary(): string {
return this._TokenIdLibrary;
}
Expand Down Expand Up @@ -249,6 +244,7 @@ export class Panoptic {
// to get multiple greeks in one call.
async queryGreeks(
wallet: Wallet,
panopticPool: string | undefined,
tick: number,
positionIdList: BigNumber[],
greek: string
Expand All @@ -258,9 +254,9 @@ export class Panoptic {
const panopticHelperContract = new Contract(panopticHelper, panopticHelperAbi.abi, wallet);
let response;
if (greek === "delta") {
response = await panopticHelperContract.delta(this.PanopticPool, wallet.address, tick, positionIdList);
response = await panopticHelperContract.delta(panopticPool, wallet.address, tick, positionIdList);
} else if (greek === "gamma") {
response = await panopticHelperContract.gamma(this.PanopticPool, wallet.address, tick, positionIdList);
response = await panopticHelperContract.gamma(panopticPool, wallet.address, tick, positionIdList);
} else {
throw new Error("Invalid greek");
}
Expand Down Expand Up @@ -837,12 +833,12 @@ export class Panoptic {
// PanopticPool interactions
async calculateAccumulatedFeesBatch(
wallet: Wallet,
panopticPool: string,
includePendingPremium: boolean = false,
positionIdList: BigNumber[]
): Promise<{ "premium0": BigNumber, "premium1": BigNumber, [key: number]: BigNumber } | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const result = await panopticPoolContract.calculateAccumulatedFeesBatch(
wallet.address,
includePendingPremium,
Expand All @@ -856,23 +852,23 @@ export class Panoptic {
}

async collateralToken0(
wallet: Wallet
wallet: Wallet,
panopticPool: string
): Promise<{"collateralToken": BigNumber} | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
return await panopticPoolContract.collateralToken0();
} catch (error) {
return new Error("Error on collateralToken0: " + (error as Error).message);
}
}

async collateralToken1(
wallet: Wallet
wallet: Wallet,
panopticPool: string
): Promise<{"collateralToken": BigNumber} | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
return await panopticPoolContract.collateralToken1();
} catch (error) {
return new Error("Error on collateralToken1: " + (error as Error).message);
Expand All @@ -881,14 +877,14 @@ export class Panoptic {

async executeBurn(
wallet: Wallet,
panopticPool: string,
burnTokenId: BigNumber,
newPositionIdList: BigNumber[],
tickLimitLow: number = this.LOWEST_POSSIBLE_TICK,
tickLimitHigh: number = this.HIGHEST_POSSIBLE_TICK
): Promise<ContractReceipt | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const gasEstimate: number = (await panopticPoolContract.estimateGas["burnOptions(uint256,uint256[],int24,int24)"](
burnTokenId,
newPositionIdList,
Expand All @@ -915,13 +911,13 @@ export class Panoptic {

async forceExercise(
wallet: Wallet,
panopticPool: string,
touchedId: BigNumber[],
positionIdListExercisee: BigNumber[],
positionIdListExercisor: BigNumber[]
): Promise<ContractReceipt | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const gasEstimate: number = (await panopticPoolContract.estimateGas.forceExercise(
wallet.address,
touchedId,
Expand All @@ -948,14 +944,14 @@ export class Panoptic {

async liquidate(
wallet: Wallet,
panopticPool: string,
positionIdListLiquidator: BigNumber[],
liquidatee: BigNumber,
delegations: number,
positionIdList: BigNumber[]
): Promise<ContractReceipt | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const gasEstimate: number = (await panopticPoolContract.estimateGas.liquidate(
positionIdListLiquidator,
liquidatee,
Expand All @@ -982,15 +978,15 @@ export class Panoptic {

async executeMint(
wallet: Wallet,
panopticPool: string,
positionIdList: BigNumber[],
positionSize: BigNumber,
effectiveLiquidityLimit: BigNumber,
tickLimitLow: number = this.LOWEST_POSSIBLE_TICK,
tickLimitHigh: number = this.HIGHEST_POSSIBLE_TICK
): Promise<ContractReceipt | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const gasEstimate: number = (await panopticPoolContract.estimateGas.mintOptions(
positionIdList,
positionSize,
Expand Down Expand Up @@ -1018,11 +1014,11 @@ export class Panoptic {
}

async numberOfPositions(
wallet: Wallet
wallet: Wallet,
panopticPool: string
): Promise<{"_numberOfPositions": BigNumber} | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
return await panopticPoolContract.numberOfPositions(wallet.address);
} catch (error) {
return new Error("Error on numberOfPositions: " + (error as Error).message);
Expand All @@ -1031,11 +1027,11 @@ export class Panoptic {

async optionPositionBalance(
wallet: Wallet,
panopticPool: string,
tokenId: BigNumber
): Promise<{"balance": BigNumber, "poolUtilization0": BigNumber, "poolUtilization1": BigNumber} | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
return await panopticPoolContract.optionPositionBalance(
wallet.address,
tokenId
Expand All @@ -1046,11 +1042,11 @@ export class Panoptic {
}

async pokeMedian(
wallet: Wallet
wallet: Wallet,
panopticPool: string
): Promise<ContractReceipt | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const gasEstimate: number = (await panopticPoolContract.estimateGas.pokeMedian()).toNumber();
const gasLimit: number = Math.ceil(this.gasLimitCushionFactor * gasEstimate);
if (gasLimit > this.absoluteGasLimit) {
Expand All @@ -1068,13 +1064,13 @@ export class Panoptic {

async settleLongPremium(
wallet: Wallet,
panopticPool: string,
positionIdList: BigNumber[],
owner: BigNumber,
legIndex: BigNumber
): Promise<ContractReceipt | Error> {
try {
const panopticpool = this.PanopticPool;
const panopticPoolContract = new Contract(panopticpool, panopticPoolAbi.abi, wallet);
const panopticPoolContract = new Contract(panopticPool, panopticPoolAbi.abi, wallet);
const gasEstimate: number = (await panopticPoolContract.estimateGas.settleLongPremium(
positionIdList,
owner,
Expand Down
Loading
Loading