# GemJoin

[Git Source](https://github.com/Ion-Protocol/ion-protocol/blob/88cc595825f1dc2eb738fb93e172a3e8ab7a5c43/src/join/GemJoin.sol)

**Inherits:** Ownable2Step, Pausable

Collateral deposits are held independently from the `IonPool` core contract, but credited to users through `gem` balances.

*Separating collateral deposits from the core contract allows for handling tokens with non-standard behavior, if needed. This contract implements access control through `Ownable2Step`. This contract implements pausing through OpenZeppelin's `Pausable`.*

### [State Variables](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#state-variables" id="state-variables"></a>

#### [GEM](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#gem" id="gem"></a>

```
IERC20 public immutable GEM;
```

#### [POOL](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#pool" id="pool"></a>

```
IonPool public immutable POOL;
```

#### [ILK\_INDEX](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#ilk_index" id="ilk_index"></a>

```
uint8 public immutable ILK_INDEX;
```

#### [totalGem](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#totalgem" id="totalgem"></a>

```
uint256 public totalGem;
```

### [Functions](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#functions" id="functions"></a>

#### [constructor](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#constructor" id="constructor"></a>

Creates a new `GemJoin` instance.

```
constructor(IonPool _pool, IERC20 _gem, uint8 _ilkIndex, address owner) Ownable(owner);
```

**Parameters**

| Name        | Type      | Description                                                     |
| ----------- | --------- | --------------------------------------------------------------- |
| `_pool`     | `IonPool` | Address of the `IonPool` contract.                              |
| `_gem`      | `IERC20`  | ERC20 collateral to be associated with this `GemJoin` instance. |
| `_ilkIndex` | `uint8`   | of the associated collateral.                                   |
| `owner`     | `address` | Admin of the contract.                                          |

#### [pause](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#pause" id="pause"></a>

Pauses the contract.

*Pauses the contract.*

```
function pause() external onlyOwner;
```

#### [unpause](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#unpause" id="unpause"></a>

Unpauses the contract.

*Unpauses the contract.*

```
function unpause() external onlyOwner;
```

#### [join](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#join" id="join"></a>

Converts ERC20 token into gem (credit inside of the `IonPool`'s internal accounting).

*Gem will be sourced from `msg.sender` and credited to `user`.*

```
function join(address user, uint256 amount) external whenNotPaused;
```

**Parameters**

| Name     | Type      | Description           |
| -------- | --------- | --------------------- |
| `user`   | `address` | to credit the gem to. |
| `amount` | `uint256` | of gem to add. \[WAD] |

#### [exit](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#exit" id="exit"></a>

Debits gem from the `IonPool`'s internal accounting and withdraws it into ERC20 token.

*Gem will be debited from `msg.sender` and sent to `user`.*

```
function exit(address user, uint256 amount) external whenNotPaused;
```

**Parameters**

| Name     | Type      | Description                            |
| -------- | --------- | -------------------------------------- |
| `user`   | `address` | to send the withdrawn ERC20 tokens to. |
| `amount` | `uint256` | of gem to remove. \[WAD]               |

### [Errors](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#errors" id="errors"></a>

#### [Int256Overflow](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#int256overflow" id="int256overflow"></a>

```
error Int256Overflow();
```

#### [WrongIlkAddress](https://docs.ionprotocol.io/devs/smart-contract-architecture/join/broken-reference) <a href="#wrongilkaddress" id="wrongilkaddress"></a>

```
error WrongIlkAddress(uint8 ilkIndex, IERC20 gem);
```


---

# 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://docs.ionprotocol.io/devs/smart-contract-architecture/join/gemjoin.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.
