# PlusPool

이 컨트랙트는 KLAYswap의 플러스 풀 유동성 제공자의 활용 자산을 관리합니다. 유동성 제공자는 예치자산에 따라 플러스 예치를 사용하여 플러스자산(예치자산+활용자산)으로 수익을 극대화할 수 있습니다. 그러나 높은 자산활용 비율은 자동 반환을 일으켜 손실을 볼 수 있습니다.          &#x20;

## Address

* Contract adress after production is deployed (scope link)&#x20;

## Events, Read-Only Functions, and State-Changing Functions

{% tabs %}
{% tab title="Events" %}

## Events

**ChangeBorrowFactor**

```solidity
event ChangeBorrowFactor(uint newBorrowFactor);
```

* LTV 변경시 발생하는 이벤트

**ChangeLiquidationFactor**

```solidity
event ChangeLiquidationFactor(uint newLiquidationFactor);
```

* 임계 자동반환 비율 변경시 발생하는 이벤트

**ChangeBorrowable**

```solidity
event ChangeBorrowable(address token, bool b);
```

* 활용가능여부 변경시 발생하는 이벤트

**GiveReward**

```solidity
event GiveReward(address user, uint amount, uint lastIndex, uint rewardSum);
```

* KSP 보상 지급시 발생하는 이벤트&#x20;

**GiveAirdropReward**

```solidity
event GiveAirdropReward(address user, address dist, uint amount, uint currentIndex, uint userAirdropSum);
```

* Airdrop 보상 지급시 발생하는 이벤트

**OpenPosition**

```solidity
event OpenPosition(address user, uint amountA, uint amountB, uint borrowA, uint borrowB, uint amountLP, uint userLP);
```

* 플러스 예치시 발생하는 이벤트
* Parameters
  * user : 사용자 주소&#x20;
  * amountA : tokenA 의 담보 수량
  * amountB : tokenB 의 담보 수량
  * borrowA : tokenA 의 활용 수량
  * borrowB: tokenB 의 활용 수량&#x20;
  * amountLP: 예치 LP 수량
  * userLP : 유저 총 예치 LP 수량&#x20;

**ClosePosition**

```solidity
event ClosePosition(address user, uint amountLP, uint amountA, uint amountB, uint userLP);
```

* 플러스 예치 출금시 발생하는 이벤트
* Parameters
  * user : 사용자 주소&#x20;
  * amountLP : 출금 LP 수량&#x20;
  * amountA : 출금된 tokenA 수량
  * amountB : 출금된 tokenB 수량
  * userLP : 유저 총 예치 LP 수량&#x20;

**Liquidate**

```solidity
event Liquidate(address user, uint idx, uint debtA, uint debtB, uint lp, uint debtRatio, uint time);
```

* 자동 반환시 발생하는 이벤트
* Parameters
  * user : 사용자 주소&#x20;
  * idx : 사용자 누적 자동 반환 횟수 &#x20;
  * deptA : 자동 반환된 tokenA 수량
  * deptB : 자동 반환된 tokenB 수량
  * lp : 유저 예치 LP 수량&#x20;
  * debtRatio : 자동 반환시 자산 활용 비율
  * time : 자동 반환 발생시간   &#x20;

{% endtab %}

{% tab title="Read-Only Functions" %}

## Read-Only Functions

#### totalLP

* 플러스 자산으로 예치중인 총 LP 수량

**lpToken**

* 활용 자산을 사용해 획득할 수 있는 유동성풀 LP 주소

#### tokenA

* 유동성 풀의 첫번째 토큰의 주소

#### tokenB

* 유동성 풀의 두번째 토큰의 주소

#### borrowableA

* tokenA 활용 가능 여부

#### borrowableB

* tokenB 활용 가능 여부

#### liquidationFactor

* 자동 반환 기준 지표&#x20;
* 1 \~ 10^18, 단위 0.000000000000000001
* 기본 - 850000000000000000

#### borrowFactor

* 활용 자산의 활용 비용 이율&#x20;
* 1 \~ 10^18, 단위 0.000000000000000001
* 기본 - 750000000000000000

#### userLP

* 플러스 자산으로 예치중인 LP 수량

#### liquidationBonusRate

* KSP 바이백 & 소각으로 사용될 재원 비율

#### liquidationCount

```
function liquidationCount(address user) public view returns (uint)
```

* 사용자의 누적 자동 반환 횟수를 반환

{% endtab %}

{% tab title="State-Changing Functions" %}

## State-Changing Functions

#### claimReward

```solidity
function claimReward() public
```

* 보상 청구 함수
* 호출시 누적된 KSP 보상이 지급되며 Airdrop 보상이 존재할 경우 함께 사용자 지갑으로 전송
* 사용자가 직접 호출하지 않는 경우에도 아래와 같은 경우에 자동으로 호출
  * 플러스 예치를 추가로 할 경우
  * 예치된 자산을 출금할 경우

#### openPosition

```solidity
function openPosition(uint amountA, uint amountB, uint borrowA, uint borrowB, uint minAmountLP) public payable
```

* 플러스 자산 예치 함수
* tokenA가 KLAY 일 경우 `amountA` 를 `msg.value` 값을 사용
* 실행이 완료된 후 사용자의 지갑으로 LP token 생성
* Parameter
  * amountA : 예치할 사용자의 tokenA 수량
  * amountB : 예치할 사용자의 tokenB 수량&#x20;
  * borrowA : 활용 자산으로 사용할 tokenA 수량
  * borrowB : 활용 자산으로 사용할 tokenB 수량&#x20;
  * minAmountLP : 슬리피지 존재시 최소 보장 LP 수량

#### closePosition

```solidity
function closePosition(uint amountLP, uint minAmountA, uint minAmountB) public
```

* 플러스 자산 출금 함수
* 실행이 완료된 후 사용자의 지갑으로 tokenA, tokenB 전송
* Parameters
  * amountLP : 출금할 사용자의 LP 수량
  * minAmountA : 슬리피지 존재시 최소 보장 tokenA 수량&#x20;
  * minAmountB : 슬리피지 존재시 최소 보장 tokenB 수량

{% endtab %}
{% endtabs %}


---

# 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.klayswap.com/kr/developer/contract/pluspool.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.
