# OneClick Contracts

### `provideETH`

Use this function when you need to provide ETH to a margin account.&#x20;

1. Wrap ETH to WETH
2. Deposit WETH to a margin account

**Example on TS:**

```typescript
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.&#x20;

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:**

```typescript
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.&#x20;

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.

```typescript
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.&#x20;

{% hint style="info" %}
Please note that this action will lower your margin ratio since you're withdrawing collateral from the margin account to purchase an option.&#x20;
{% endhint %}

```typescript
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&#x20;

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

```typescript
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
)
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharwa.gitbook.io/sharwa-docs/for-devs/margin-account/toolkits-and-other-contracts/oneclick-contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
