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

chore: add a gas estimation guide #127

Merged
merged 1 commit into from
Jul 21, 2023
Merged
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
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,31 @@ const liquidity = perp.liquidities.getTotalLiquidities().filter(filterFn)
perp.clearingHouse.removeLiquidity(liquidity, ratio, slippage)
```

## Gas Estimation Guide

The current version of the SDK does not support for configuring `maxFeePerGas` and `maxPriorityFeePerGas`. It relies on the gas settings defined by the provider as defaults. After the Optimism Bedrock upgrade, gas fees have become volatile and can sometimes be extremely high. If this happens, we recommend using alternative library, such as [ethers.js](https://www.npmjs.com/package/ethers), to send transactions. Here's an example:

```ts
// example of open position using ethers.js
import { StaticJsonRpcProvider } from "@ethersproject/providers"
import { parseUnits } from "@ethersproject/units"
import { Contract, Wallet } from "ethers"

// create clearing house
const provider = new StaticJsonRpcProvider(endpointUrl)
const wallet = new Wallet(privateKey, provider)
const clearingHouse = new Contract(clearingHouseAddress, clearingHouseAbi, wallet)

// set appropriate gas fee
const feeData = await provider.getFeeData()
const maxFeePerGas = feeData.lastBaseFeePerGas.mul(2)
const maxPriorityFeePerGas = parseUnits("0.001", "gwei")

// send tx
const tx = await clearingHouse.openPosition(openPositionParams, { maxFeePerGas, maxPriorityFeePerGas })
await tx.wait()
```

---

> If any features/functionalities described in the Perpetual Protocol documentation, code comments, marketing, community discussion or announcements, pre-production or testing code, or other non-production-code sources, vary or differ from the code used in production, in case of any dispute, the code used in production shall prevail.
Loading