Sharwa.Finance Documentation
  • 💼Margin Account
    • Liquidity Providers
      • Insurance Pool
    • Liquidation
    • Fees
    • Allowed Assets
    • Security
    • Links
  • 🪙Tokenomics
    • We don't have a token
  • 🦾FOR DEVS
    • Margin Account
      • Core Contracts
        • MarginTrading.sol
        • MarginAccountManager.sol
        • LiquidityPool.sol
        • ModularSwapRouter
          • HegicModule.sol
      • Toolkits and other contracts
        • OneClick Contracts
      • HegicStopOrders
        • HegicStopOrders SDK
  • 📚Guide
    • How To Trade on Sharwa
Powered by GitBook
On this page
  • provideETH
  • borrowSwap
  • swapRepay
  • withdrawProvideERC721
  • transferBuyProvideERC721
  1. FOR DEVS
  2. Margin Account
  3. Toolkits and other contracts

OneClick Contracts

OneClick Contracts zaps multiple actions into one transaction. You can use this function to enhance your user experience with Sharwa.

provideETH

Use this function when you need to provide ETH to a margin account.

  1. Wrap ETH to WETH

  2. Deposit WETH to a margin account

Example on TS:

await OneClickMarginTrading.provideETH(
    1, //margin account id
    {value: parseEther("0.001")} // ETH amount
)

borrowSwap

Use this function when you need to open Long or Short position in one transaction.

  1. Borrow Token "A"

  2. Swap token "A" for token "B"

For example, borrow ETH and sell it for USDC to open a Short position on ETH within one transaction.

Example on TS:

await OneClickMarginTrading.borrowSwap(
    1, //margin account iD 
    await USDC.getAddress() // token address to sell
    await WETH.getAddress(), // token address to buy
    parseUnits("3", await USDC.decimals()), // token amount to sell
    0 // minumum token to receive (slippage control)
)

swapRepay

Use this function when you want to close a position and repay the debt in one transaction.

  1. Swap token "A" for token "B"

  2. Repay the debt for token "B"

Example: Borrow USDC and swap it for ETH. Then fix the profits by selling ETH for USDC and repaying the debt in one transaction.

await OneClickMarginTrading.swapRepay(
    1, // margin account ID
    await WETH.getAddress(), // token address to sell
    await USDC.getAddress(),  // token address to buy
    parseUnits("3", await USDC.decimals()), // token amount to sell
    0 // min. token to receive (slippage control)
)

withdrawProvideERC721

Use this function when you want to purchase an option on Hegic using collateral from your margin account

  1. Withdraw token "A" from a margin account

  2. Swap token "A" for USDC.e

  3. Purchase an option on Hegic

  4. Deposit Hegic Option (ERC-721) to the margin account

Example: purchase an option position using collateral from the margin account.

Please note that this action will lower your margin ratio since you're withdrawing collateral from the margin account to purchase an option.

await OneClickMarginTrading.withdrawBuyProvideERC721(
    1, // margin account id
    await USDC.getAddress(), // token address to pay
    HegicStrategy_CALL_100_ETH_1, // address of hegic strategy
    parseUnits("0.00001", 18), // amount of options to buy
    MaxUint256, // ma
    60*60*24*7, //option period in seconds
    [] // additional parameters for a strategy
)

transferBuyProvideERC721

Use this function when you want to purchase an option on Hegic using funds from your wallet and deposit the purchased option to the margin account.

  1. Swaps token "A" from the user's wallet (works only with WETH, WBTC and USDC)

  2. Swaps token "A" for USDC.e

  3. Purchase an option on Hegic

  4. Provide Hegic Option (ERC-721) to a margin account

Example: purchase an option option position to hedge your margin account using funds from your wallet.

await OneClickMarginTrading.transferBuyProvideERC721(
    1, //margin account id
    await USDC.getAddress(), // token address which is used as a payment
    HegicStrategy_CALL_100_ETH_1, //address of a hegic strategy
    parseUnits("0.00001", 18), //amount of options
    MaxUint256, //maximum premium that you'll be charged in USDC.e (slippage)
    60*60*24*7, //option period in seconds
    [] //additional parameters for a strategy
)

PreviousToolkits and other contractsNextHegicStopOrders

Last updated 3 months ago

🦾