Before you begin
- Have an open position from the Quickstart. The examples use its settings,
send()helper,ERC20_ABI, andFACTORY_ABI. - Wait until each open of the position is confirmed, about 30 seconds after it is mined. Before that, the roll quote returns
409PositionConfirming. - The new instrument must have the same underlying, option type, collateral, quote token, and Greek Factory as the position. It must be a different instrument.
- A position on a retired Greek Factory cannot roll. Close it, then open a new position.
- A roll always uses the full remaining position. To roll part of a position, close part of it first.
- The wallet needs USDC for the close premium and ETH for gas.
1
Find the position
2
Choose the new instrument
List the instruments with the same underlying and option type. Choose one where
canSell is true and factory is the Greek Factory of the position. The example chooses the first instrument with a later expiry. Change the selection to the strike and the expiry that you want.3
Grant the full permission mask
A roll burns the old option tokens and mints the new option tokens in one transaction. The settlement contract needs mask
7 (TRANSFER | MINT | BURN). If you granted 3 and 4 before, the mask is already 7.4
Approve the collateral and the USDC
The close leg settles first, so the wallet pays the close premium before it receives the open premium.
- Approve the collateral to the Greek Factory for the new amount. For a call, the new amount is the remaining amount. For a put, it is the remaining amount times the new strike divided by the old strike, rounded down.
- Approve USDC to the settlement contract for the largest close premium that you accept, in raw units (6 decimals). For a call, the wallet must also hold that USDC.
5
Request a roll quote
netPremium is the open premium received minus the close premium paid, in raw USDC units. A negative value is a payment by the wallet. collateralDelta is the new collateral locked minus the collateral released. It is "0" for a call.6
Send the transaction
Send
tx from the wallet before expiry. Do not change tx.data.7
Verify the result
Bebop indexes the transaction some seconds after it is mined. Then the old position has
status closed, and the position with the ID open.positionId from the roll quote is open.