# Contract Guide

> These guidelines are fully hardcoded into the Helemet Smart Contract(s).The various parameters of the helmet platform are fully market-priced and contracts are automatically executed. Helmet team will not intervene in the policy price at any time or make changes to the contract unless it is necessary.

### Guide book to Helmet Smart Contracts&#x20;

Helmet.insurance's smart contracts are divided into core and peripheral two parts. The option logic is implemented in the core, including the **OptionFactory**, **LongOption**, and **ShortOption** contracts, the periphery implements policy buying and selling and flat-rate farming and harvesting, including the **OptionOrder**, **HELMET Token**, and **Farm contracts**.

**OptionFactory** is used for creating insurance policy contracts, minting Tokens, destroying Tokens, enabling policy activated and settlement.&#x20;

* LongOption is the buyer's certificate to activate the policy.
* ShortOption is the seller's certificate for clearing back the denominated and the underlying assets.
* OptionOrder is the policy marketplace, where supplier publish policies and holders buy policies, as well as the entry point for buyers to activate policy.

#### OptionFactory main function:

`function createOption(bool _private, address _collateral, address _underlying, uint _strikePrice, uint _expiry) public returns (address long, address short);`

`function mint(bool _private, address _collateral, address _underlying, uint _strikePrice, uint _expiry, uint volume) public returns (address long, address short, uint vol);`

`function burn(address _creator, address _collateral, address _underlying, uint _strikePrice, uint _expiry, uint volume) public returns (address long, address short, uint vol);`

`function calcExerciseAmount(address _long, uint volume) public view returns (uint);`&#x20;

`function exercise(address _long, uint volume, address[] memory path) public returns (uint vol, uint fee, uint amt);`&#x20;

`function settleable(address short, uint volume) public view returns (uint vol, uint col, uint fee, uint und);`&#x20;

`function settle(address short, uint volume) public returns (uint vol, uint col, uint fee, uint und);`&#x20;

#### LongOption main function：

`function exercise(uint volume, address[] memory path) public returns (uint vol, uint fee, uint amt);`&#x20;

#### ShortOption main function：

`function settleable(address seller) public view returns (uint vol, uint col, uint fee, uint und);`&#x20;

`function settle(uint volume) external returns (uint vol, uint col, uint fee, uint und);`&#x20;

#### OptionOrder main function：

`function sell(bool _private, address _collateral, address _underlying, uint _strikePrice, uint _expiry, uint volume, address settleToken, uint price) virtual public returns (uint askID);`&#x20;

`function reprice(uint askID, uint newPrice) virtual external returns (uint newAskID);`&#x20;

`function cancel(uint askID) virtual external returns (uint vol);`&#x20;

`function buy(uint askID, uint volume) virtual public returns (uint bidID, uint vol, uint amt);`&#x20;

`function exercise(uint bidID, uint volume, address[] memory path) virtual public returns (uint vol, uint fee, uint amt);`&#x20;

`function waive(uint bidID, uint volume) virtual public returns (uint vol);`&#x20;

## Buy\&Sell

### &#xD;sell a policy

Using the `sell function` of the OptionOrder contract.：

```javascript
 function sell(
     bool _private, 
     address _collateral, 
     address _underlying, 
     uint _strikePrice, 
     uint _expiry, 
     uint volume, 
     address settleToken, 
     uint price
 ) 
     virtual 
     public 
     returns (uint askID);
```

Example

| <p><strong>Denominated</strong> </p><p><strong>Asset</strong></p> | <p><strong>Underlying</strong> </p><p><strong>Asset</strong></p> | <p>Policy </p><p>Price</p> | **Premium** | Amount |    <p>Expeir </p><p>At</p>    |
| :---------------------------------------------------------------: | :--------------------------------------------------------------: | :------------------------: | :---------: | ------ | :---------------------------: |
|                                BNB                                |                              HELMET                              |           0.1BNB           |  0.2 Helmet | 10 BNB | <p>2021/1/1 <br>0:0:0 UMT</p> |

```javascript
OptionOrder.sell(
    false, 
    0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, 
    0x4E76DfeA6Fb3726e9A77628AAa23839E3298BC37, 
    10000000000000000000, 
    1609459200, 
    123000000000000000000, 
    0x4E76DfeA6Fb3726e9A77628AAa23839E3298BC37, 
    200000000000000000);
```

### Buy a policy

Using the `buy function` of the OptionOrder contract.：&#x20;

```javascript
function buy(uint askID, uint volume) 
    virtual 
    public 
    returns (uint bidID, uint vol, uint amt);
```

Example

| ID  | Policy price |
| --- | ------------ |
| 456 | 123bnb       |

```javascript
OptionOrder.buy(456, 123000000000000000000);
```

### Activate the policy

Using the `exercise function` of the OptionOrder contract.：&#x20;

```javascript
function exercise(
    uint bidID, 
    uint volume, 
    address[] memory path
) 
    virtual 
    public 
    returns (uint vol, uint fee, uint amt);
```

Example:

if it's a cover off policy&#x20;

```javascript
OptionOrder.exercise(789, 123000000000000000000, []);
```

If it's a cover up policy&#x20;

```javascript
OptionOrder.exercise(
    789, 
    123000000000000000000, 
    [0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c,
    0x4E76DfeA6Fb3726e9A77628AAa23839E3298BC37]);
```

### Get back the settlement

Using the `settle function` of the OptionFactory contract:

```javascript
function settle(
    address _creator, 
    address _collateral, 
    address _underlying, 
    uint _strikePrice, 
    uint _expiry, 
    uint volume
) 
    external 
    returns (uint vol, uint col, uint fee, uint und);
```

Example&#x20;

```javascript
OptionFactory.settle(
    address(0), 
    0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, 
    0x4E76DfeA6Fb3726e9A77628AAa23839E3298BC37, 
    10000000000000000000, 
    1609459200, 
    123000000000000000000);
```


---

# 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://helmet-insure.gitbook.io/helmet/contract-guide.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.
