Skip to content

Releases: StrobeLabs/perpcity-sdk

v0.14.1 — Complete PERP_ABI with trade/position events

Choose a tag to compare

@lukemacauley lukemacauley released this 09 Jul 16:13
Immutable release. Only release title and notes can be modified.
4c7c648

Re-release of 0.14.0 (which failed to publish — Node 20 / npm@latest breakage, fixed in #59; the v0.14.0 tag is reserved by immutable releases). No source changes.

Added

PERP_ABI now includes all 20 Perp trade/position "free events" that forge inspect omits — TakerOpened, TakerAdjusted, TakerClosed, TakerBackstopped, the five Maker* events, plus pool/market-state and tick events (MarginTransferred, OpenInterestUpdated, RatesAndEmasRefreshed, CumulativesAccrued, CapacityUpdated, Donated, LossSocialized, BadDebtAccounted, TickInitialized, TickDeleted, TicksCrossed).

Consumers can now decodeEventLog({ abi: PERP_ABI, ... }) on any Perp trade log. Vendored from the deployed v0.1.0 contract; all 20 topic0 selectors verified against the indexer ABI. See #58.

v0.13.0

Choose a tag to compare

@lukemacauley lukemacauley released this 08 Jul 14:49
Immutable release. Only release title and notes can be modified.
59f892a

Adjust primitives for position adjustment:

  • adjustTaker / adjustMaker / adjustMargin now await transaction receipts and throw on revert (aligned with open/close). Return shape unchanged.
  • estimateTakerAdjust: quote an arbitrary signed adjust delta via the client-side swap model (no eth_call).
  • buildAdjustTakerCalls / buildAdjustMakerCalls: approve+adjust call batches for gasless userOp submission.

v0.12.0 — Multicall batching on the public client

Choose a tag to compare

@lukemacauley lukemacauley released this 06 Jul 20:35
Immutable release. Only release title and notes can be modified.
a96c15a

Client-level viem batch.multicall: concurrent readContract reads aggregate into a single Multicall3 aggregate3 eth_call (one billed RPC request instead of N). Transport-level HTTP batching kept for non-aggregatable requests; the estimateLiquidity margin probe opts out (batch: false) to preserve its revert-marker semantics. Chains without a configured Multicall3 fall back to individual calls automatically.

See CHANGELOG.md for details.

v0.11.0 — Maker liquidity sized to the on-chain margin check

Choose a tag to compare

@lukemacauley lukemacauley released this 03 Jul 15:31
Immutable release. Only release title and notes can be modified.
541e3d3

LP opens no longer revert with MarginRatioTooLow at the sizes the SDK itself recommends.

Changed

  • Breaking: estimateLiquidity now requires the perp address as its second argument: estimateLiquidity(context, perpAddress, tickLower, tickUpper, usdScaled).
  • estimateLiquidity sizes liquidity to the on-chain maker margin check instead of the naive amount1 formula. The old formula targeted a notional exactly equal to the margin, which the contract's rounding pushed 1-2 units past the 100% maker initial margin ratio. The estimate now:
    • values below-range positions exactly, replicating the contract rounding (max healthy liquidity is floor((margin - 2) * Q96 / sqrtPriceDiff), validated against mainnet);
    • values straddling and above-range positions at the larger of the AMM price and beacon index (ranges above the current price were previously sized as USD exposure and always reverted);
    • verifies the result with an eth_call simulation of openMaker and bisects down to the true boundary when the mark price sits above both proxies.
  • getSqrtRatioAtTick rounds up the final shift to match the contract's TickMath.

v0.10.0 — Price-impacted estimateTakerPosition

Choose a tag to compare

@lukemacauley lukemacauley released this 16 Jun 15:06
Immutable release. Only release title and notes can be modified.
ad5c7e4

Quotes now reflect real AMM price impact.

Changed

  • estimateTakerPosition simulates the exact-perp-in swap against the pool curve instead of returning the flat mark price. fillPrice and usdDelta now reflect real price impact, and usdDelta is suitable to feed straight into calculateTakerSlippageLimit for an amt1Limit that won't spuriously revert with MaxAmtExceeded on shallow pools.
  • New exceedsLiquidity field on EstimateTakerPositionResult — set when an order is larger than the current active-liquidity region can fill (a strong pre-submit signal of PriceImpactTooHigh).

Added

  • PerpData exposes sqrtPriceX96 and liquidity from poolState (no new RPC).
  • simulateTakerSwap(...) utility — the constant-liquidity exact-perp-in swap math, exported for callers holding pool state.

Limitations

Single active-liquidity-region approximation: exact within the current tick, understates impact once a swap would cross an initialized tick (only current active liquidity is available, not the full per-tick map). Fees are not modeled.

See PR #53.

v0.9.0 — Tier-2 calldata builders

Choose a tag to compare

@lukemacauley lukemacauley released this 15 Jun 21:31
Immutable release. Only release title and notes can be modified.
e5967d5

Added — Tier-2 calldata builders

Raw-calldata builders for callers that submit transactions themselves (e.g. batching approve + trade into one ERC-4337 userOperation) instead of letting the SDK execute via walletClient.writeContract. Each mirrors the argument encoding of its execute-and-wait counterpart, so a built call hits the same contract path; fee headroom is omitted because userOp gas is handled by the bundler/paymaster.

  • buildApproveUsdcCall, buildOpenTakerPositionCall, buildOpenMakerPositionCall
  • buildAdjustTakerCall, buildAdjustMakerCall, buildClosePositionCall
  • buildOpenTakerPositionCalls / buildOpenMakerPositionCalls — full ordered batch that prepends a USDC approve only when allowance is short (maker covers margin + maxAmt1In)
  • CallData type ({ to, data, value })

Additive and non-breaking. See PR #52.

v0.8.3

Choose a tag to compare

@lukemacauley lukemacauley released this 12 Jun 12:03
Immutable release. Only release title and notes can be modified.
4f17708

Decode current contract errors: full custom-error ABI (MinAmtUnmet, MarginTooLow, MaxAmtExceeded, InsufficientLiquidityToFill, and friends) plus friendly messages in parseContractError — reverts no longer surface as "Contract error: Unknown".

v0.8.2

Choose a tag to compare

@lukemacauley lukemacauley released this 11 Jun 21:57
Immutable release. Only release title and notes can be modified.
64457ac

Changes

Fixes a 0.8.1 regression that broke every write on some Arbitrum providers (Alchemy): headroom fees were passed into simulateContract, and fee fields inside an eth_call make those nodes run the balance check against the RPC gas cap (uint64 max), rejecting every call with insufficient-funds.

  • Fees now merge into the prepared request at writeContract time via withFeeHeadroom; simulation requests carry no fee fields
  • Regression tests pin both request shapes (no fees in simulation, doubled fees on the write)

Full diff: v0.8.1...v0.8.2

v0.8.1

Choose a tag to compare

@lukemacauley lukemacauley released this 11 Jun 21:06
Immutable release. Only release title and notes can be modified.
5c2ebc0

Changes

  • bounds.minMargin now mirrors the contract's MIN_OPENING_MARGIN (5e6 micro-USDC = $5, was a stale hardcoded $10); exported as MIN_OPENING_MARGIN_USD
  • All write paths pass explicit maxFeePerGas with 2x headroom (estimateFeesWithHeadroom), preventing intermittent FeeCapTooLowError rejections when the base fee moves between estimation and submission (frequent on Arbitrum Sepolia)
  • parseContractError maps fee-cap-too-low failures to a retryable RPCError instead of ContractError "Unknown"

Full diff: v0.8.0...v0.8.1

v0.8.0

Choose a tag to compare

@lukemacauley lukemacauley released this 04 Jun 23:26
Immutable release. Only release title and notes can be modified.
1086fea

Added

  • calculateTakerSlippageLimit(quote, isLong, slippagePercent) — derives the contract-native amt1Limit for openTakerPosition from usdDelta (the currency1 / USD leg the contract checks in PerpLogic.checkTakerAmountLimits): a ceiling on USD paid for longs, a floor on USD received for shorts. The slippage math now lives in the SDK instead of being reimplemented per app.

Changed

  • examples/taker.ts and examples/wagmi-integration.ts use calculateTakerSlippageLimit instead of inlining the basis-point math.
  • Bumped viem from ^2.37.8 to ^2.46.1 to align with the client and remove as never walletClient casts there.
  • Switched tsconfig moduleResolution from node to bundler so the newer viem's transitive ox resolves to its bundled declarations (skipped by skipLibCheck) instead of its raw .ts source.

See #47 / #48.