Skip to content

Commit

Permalink
cap lp exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-io committed Dec 5, 2024
1 parent d11598f commit 182a671
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perennial/sdk",
"version": "0.0.3-beta.9",
"version": "0.0.3-beta.10",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
7 changes: 5 additions & 2 deletions src/utils/positionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ export const calcLeverage = (price: bigint, position: bigint, collateral: bigint
export const calcMakerExposure = (userMaker: bigint, globalMaker: bigint, globalLong: bigint, globalShort: bigint) => {
if (globalMaker === 0n) return 0n

return Big6Math.div(Big6Math.mul(userMaker, globalShort - globalLong), globalMaker)
const exposure = Big6Math.div(globalShort - globalLong, globalMaker)
const cappedExposure = Big6Math.max(Big6Math.min(exposure, Big6Math.ONE), -1n * Big6Math.ONE)

return Big6Math.mul(userMaker, cappedExposure)
}
/**
* Returns whether a position is closed or inactive
Expand Down Expand Up @@ -283,7 +286,7 @@ export function calcLpExposure(marketSnapshot?: MarketSnapshot) {
const majorPosition = majorSide === PositionSide.long ? long : short
const minorPosition = majorSide === PositionSide.long ? short : long

const lpExposure = maker > 0n ? Big6Math.div(majorPosition - minorPosition, maker) : 0n
const lpExposure = maker > 0n ? Big6Math.min(Big6Math.div(majorPosition - minorPosition, maker), Big6Math.ONE) : 0n

return {
lpExposure: lpExposure,
Expand Down

0 comments on commit 182a671

Please sign in to comment.