Pods Options
app.pods.financeGithubBlogDiscord
  • Getting Started
  • Understand Options
    • What are options?
    • How do options work?
    • Pricing Options
  • The Protocol
    • Overview
    • Safety Measures
    • Ecosystem Participants
    • Use Cases
  • Options
    • Overview
    • Options Instrument
      • Variables
      • Functions
        • Mint
        • Unmint
        • Withdraw
        • Exercise
    • Smart Contracts
      • OptionFactory
      • PodPut
      • WPodPut
      • PodCall
      • WPodCall
    • Applied Use Cases
    • Understanding Returns
  • Options AMM
    • Overview
    • Options AMM
      • Variables
      • Components
      • Functions
        • Add Liquidity
        • Re-add Liquidity
        • Trade
        • Remove Liquidity
      • Pricing
      • Find The Next IV
      • Fees
      • Scenarios
        • LP Simulations
    • Smart Contracts
      • OptionAMMPool
      • OptionAMMFactory
      • OptionPoolRegistry
    • Applied Math
  • Developers
    • System Overview
    • Deployed Contracts
    • Dev Environment
  • Interfacing with Pods
    • Brand Assets
  • Code Integration Guides
    • Integrating with Pods (video)
    • How To Create Your Own Option
    • How To Create Your Own Pool
    • How To Trade (Buy/Sell)
    • How To Exercise
    • How To Remove Liquidity
  • User Guides
    • Videos
  • Security
    • Audits
  • APPENDIX
    • FAQ
    • Glossary of Terms
  • Additional Resources
  • app.pods.finance
  • Github
  • Blog
  • Discord
  • Twitter
  • Pods v0 Docs
Powered by GitBook
On this page
  • 1. Find OptionAMMPool Address
  • 2. Get the Trade Details
  • 3. Allow the tokensB (stable tokens) or tokensA (option tokens) to be spent by the OptionAMMPool
  • 4. Perform the trade

Was this helpful?

  1. Code Integration Guides

How To Trade (Buy/Sell)

PreviousHow To Create Your Own PoolNextHow To Exercise

Last updated 3 years ago

Was this helpful?

There are a few ways to trade options from our pool. In this tutorial, we will focus on interacting directly with the . In order to do that, you will need to perform a few steps.

  1. Find the OptionAMMPool address gave a certain option using the OptionAMMFactory

  2. Get the trade details given a certain options amount you want to trade using the OptionAMMPool with the function getOptionTradeDetails

  3. Allow the tokensB (stable tokens) or the tokensA (option tokens) to be spent by the OptionAMMPool

  4. Perform the trade

1. Find OptionAMMPool Address

You will need for this step:

  1. OptionPoolRegistry contract address and ABI

In order to get OptionPoolRegistry you will need:

1) Instantiate our ConfigurationManager contract. Check our deployed contracts page .

2) Call the function getOptionPoolRegistry().

Now with the OptionPoolRegistry contract, you can call the function getPool.

You can also check this step directly on .

pragma solidity >0.6.0;
// 1) Import IOptionPoolRegistry interface
import "../interfaces/IOptionPoolRegistry.sol";
// 2) Instantiate OptionAMMFactory.
IOptionPoolRegistry optionPoolRegistry = IOptionPoolRegistry("/optionPoolRegistryAddress*/");

// 3) Get the option address you will want to buy.
address optionAddress = '0xe3...";

// 4) Call the getPool function and receive the pool address in return.
address optionAMMPoolAddress = optionPoolRegistry.getPool(optionAddress);

2. Get the Trade Details

Now that you have the pool address from the previous step, you can call one of the following view functions:

Function name

Description

getOptionTradeDetailsExactAOutput

You should pass as input the exact number of options you will want to buy.

getOptionTradeDetailsExactAInput

You should pass as input the exact number of options you will want to sell.

getOptionTradeDetailsExactBOutput

You should pass as input the exact number of stable tokens (premium) you will want to receive when selling.

getOptionTradeDetailsExactBInput

You should pass as input the exact number of stable tokens (premium) you will want to pay when buying.

In return, you will receive the amount of tokensB (stable assets) or tokensA (option tokens) and newIV. newIV will be necessary later to perform the trade.

pragma solidity >0.6.0;
// 1) Import IOptionAMMFactory interface
import "../interfaces/IOptionAMMPool.sol";

// 2) Instantiate optionAMMPool using the address you
// got from the previous step
IOptionAMMPool optionAMMPool = IOptionAMMPool(optionAMMPoolAddress);


/*
 In this example we will perform a buyExactAOuput action.
 
 3) Call the getOptionTradeDetailsExactAOutput with
    the option amount you will want to buy as an input
    
    That function returns:
    uint256 amountBIn - The amount of tokenB in order to buy amountOfOptions
    uint256 newIV - The new pool Implied volatility, also known as sigma
*/

uint256 amountOfOptions = 100000; // The option decimals can be found calling option.decimals()
(uint256 amountBIn, uint256 newIV, , ,) = optionAMMPool.getOptionTradeDetailsExactAOutput(amountOfOptions);

TokenA in the optionAMMPool will always be the option token. TokenB will always be the stable token.

3. Allow the tokensB (stable tokens) or tokensA (option tokens) to be spent by the OptionAMMPool

If you are already familiar with Ethereum development, you can jump to step 4. We will only approve the tokenA/tokenB to be spent by the pool. If you are selling, you will need to approvetokenA, but if you are buying, you will need to approve tokenB.

// 1) Get tokenB address from the pool
address tokenBAddress = optionAMMPool.tokenB();

// 2) Instantiate tokenB of the pool using ERC20 interface.
IERC20 tokenB = IERC20(tokenBAddress);

// 3) Approve optionAMMPool to spend amountToApprove 
// tokenB in your behalf

// You can use amountBIn from the previous step with
// an error.
// For example: (amountBIn + amountBIn / 10) // 10% tolerance
uint256 amountToApprove = 10000;

tokenB.approve(optionAMMPoolAddress, amountToApprove);

4. Perform the trade

/*
Using the newIV from previous step, you can use it as
the last parameter of the tradeExactAOutput function.
- Function inputs:
 uint256 exactAmountAOut - Amount of options to buy
 uint256 maxAmountBIn - Slippage control
 address owner - Amount of options to buy
 uint256 sigmaInitialGuess - mewIV found in previous step
*/
// Examples below;
optionAMMPool.tradeExactAOutput(
  amountOfOptions,
  maxAmountBIn,
  owner,
  newIV
 );
 

Now, finally, you are ready to perform the trade. You can check the full function specification .

OptionAMMPool
here
getPool function
here
Option series address