🥭Option

Short(Mint) Option

In Volare, we use a unique ERC20 token called VToken to represent the Option. To create this token from the void, we need to start the operation of the short option, which corresponds to the mint operation among the Defi world.

In our example, we will create a wallet from the ground up and show you how the wallet is used. The same object can be used in later code snippets.

const tx = await vanilla.short(
  wallet,
  vToken, // VToken object
  amount // The target amount of VToken you want to have. 
);

// You can process the transaction receipt in tx.wait() function.

Notice

The amount here is the VToken you will get in your wallet. Aware of the collateral difference between call and put options. All information about the Product and VToken can be found in their query APIs. While using the SDK, there's no need to handle the decimals or ERC20 contract approval problem; we have done it for you. But you have to pay extra attention to the calculation among float numbers.

Settle Option

After the option expired, you will have to settle the option. In Volare, each short option has a unique Vault ID. The settle option operation use Vault ID to trace and settle the option. You can use the API we provide to list the short expired options, then determine which option to settle.

In our case, we use fetch to make the HTTP request. The request might miss in some older versions of Node.js; you can use any alternative network request library to avoid the hassle of polyfill.

// The conversion is only for the compatibility of params object
const params = new URLSearchParams({
  address: wallet.address, // in browser, get address with signer.getAddress()
  isExpired: expired.toString(),
  withVToken: withVToken.toString(),
  isSettled: "false",
});
const data = await fetch(
  `${API_ENDPOINT}/eth/volare/vTokens/shorts?${params}`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
  }
)

// Select one option from the result above

// The settle function will return a promise contains a
// standard ethers.js transaction response
const tx = await volare.settle(wallet, 1);

Redeem Option

After the option expires, you might want to redeem the option. Redeem is a bit different from settle. You must pass the VToken object and an amount to redeem your options.

const params = new URLSearchParams({
  address: wallet.address, // in browser, get address with signer.getAddress()
  isExpired: expired.toString(),
  withVToken: withVToken.toString(),
  isRedeemed: "false",
});
const data = await fetch(
  `${API_ENDPOINT}/eth/volare/vTokens/longs?${params}`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
  }
);

const tx = await volare.redeem(
  wallet, 
  vToken, // The VToken object fetch from API
  2.58 // The VToken amount you want to redeem
);

Last updated