How To Trade (Buy/Sell)
There are a few ways to trade options from our pool. In this tutorial, we will focus on interacting directly with the OptionAMMPool. In order to do that, you will need to perform a few steps.
Find the
OptionAMMPooladdress gave a certain option using theOptionAMMFactoryGet the trade details given a certain options amount you want to trade using the
OptionAMMPoolwith the functiongetOptionTradeDetailsAllow the
tokensB(stable tokens) or thetokensA(option tokens) to be spent by theOptionAMMPoolPerform the trade
1. Find OptionAMMPool Address
OptionAMMPool AddressYou will need for this step:
OptionPoolRegistry contract address and ABI
In order to get OptionPoolRegistry you will need:
1) Instantiate our ConfigurationManager contract. Check our deployed contracts page here.
2) Call the function getOptionPoolRegistry().
Now with the OptionPoolRegistry contract, you can call the function getPool.
You can also check this step directly on getPool function.
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.
3. Allow the tokensB (stable tokens) or tokensA (option tokens) to be spent by the OptionAMMPool
tokensB (stable tokens) or tokensA (option tokens) to be spent by the OptionAMMPoolIf 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.
4. Perform the trade
Now, finally, you are ready to perform the trade. You can check the full function specification here.
Last updated