> For the complete documentation index, see [llms.txt](https://docs.frax.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.frax.finance/zh/abi-and-code.md).

# ABI & Code

## **公共代码库**

{% embed url="<https://github.com/FraxFinance/fraxlend>" %}

## **ABI**

### FraxlendPairCore <a href="#fraxlendpaircore" id="fraxlendpaircore"></a>

一个抽象合约，其中包含 FraxlendPair 的核心逻辑和存储。

### 构造函数

```solidity
constructor(bytes _configData, bytes _immutables, uint256 _maxLTV, uint256 _liquidationFee, uint256 _maturityDate, uint256 _penaltyRate, bool _isBorrowerWhitelistActive, bool _isLenderWhitelistActive) internal
```

构造函数在合约部署时被调用。

| Param                       | Type    | Description                                                                                                                                                                             |
| --------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_configData                | bytes   | abi.encode(address \_asset, address \_collateral, address \_oracleMultiply, address \_oracleDivide, uint256 \_oracleNormalization, address \_rateContract, bytes memory \_rateInitData) |
| \_immutables                | bytes   |                                                                                                                                                                                         |
| \_maxLTV                    | uint256 | The Maximum Loan-To-Value for a borrower to be considered solvent (1e5 precision)                                                                                                       |
| \_liquidationFee            | uint256 | The fee paid to liquidators given as a % of the repayment (1e5 precision)                                                                                                               |
| \_maturityDate              | uint256 | The maturityDate date of the Pair                                                                                                                                                       |
| \_penaltyRate               | uint256 | The interest rate after maturity date                                                                                                                                                   |
| \_isBorrowerWhitelistActive | bool    | Enables borrower whitelist                                                                                                                                                              |
| \_isLenderWhitelistActive   | bool    | Enables lender whitelist                                                                                                                                                                |

### 初始化 <a href="#initialize" id="initialize"></a>

```solidity
function initialize(string _name, address[] _approvedBorrowers, address[] _approvedLenders, bytes _rateInitCallData) external
```

初始化函数`initialize`在部署后立即被调用。

此函数只能由部署者调用。

| Param               | Type       | Description                                             |
| ------------------- | ---------- | ------------------------------------------------------- |
| \_name              | string     | The name of the contract                                |
| \_approvedBorrowers | address\[] | An array of approved borrower addresses                 |
| \_approvedLenders   | address\[] | An array of approved lender addresses                   |
| \_rateInitCallData  | bytes      | The configuration data for the Rate Calculator contract |

### \_totalAssetAvailable <a href="#totalassetavailable" id="totalassetavailable"></a>

```solidity
function _totalAssetAvailable(struct VaultAccount _totalAsset, struct VaultAccount _totalBorrow) internal pure returns (uint256)
```

`_totalAssetAvailable` 函数返回合约中资产代币的总余额。

| Param         | Type                | Description                                                          |
| ------------- | ------------------- | -------------------------------------------------------------------- |
| \_totalAsset  | struct VaultAccount | VaultAccount struct which stores total amount and shares for assets  |
| \_totalBorrow | struct VaultAccount | VaultAccount struct which stores total amount and shares for borrows |

| Return | Type    | Description                                  |
| ------ | ------- | -------------------------------------------- |
| \[0]   | uint256 | The balance of Asset Tokens held by contract |

### \_isSolvent <a href="#issolvent" id="issolvent"></a>

```solidity
function _isSolvent(address _borrower, uint256 _exchangeRate) internal view returns (bool)
```

`_isSolvent` 函数用于判断在给定的汇率下，特定借款人是否具备偿还能力。

| Param          | Type    | Description                                                        |
| -------------- | ------- | ------------------------------------------------------------------ |
| \_borrower     | address | The borrower address to check                                      |
| \_exchangeRate | uint256 | The exchange rate, i.e. the amount of collateral to buy 1e18 asset |

| Return | Type | Description                 |
| ------ | ---- | --------------------------- |
| \[0]   | bool | Whether borrower is solvent |

### \_isPastMaturity <a href="#ispastmaturity" id="ispastmaturity"></a>

```solidity
function _isPastMaturity() internal view returns (bool)
```

`_isPastMaturity` 函数用于判断当前区块时间戳是否已经超过到期日期（maturityDate）。

| Return | Type | Description                              |
| ------ | ---- | ---------------------------------------- |
| \[0]   | bool | Whether or not the debt is past maturity |

### isSolvent <a href="#issolvent-1" id="issolvent-1"></a>

```solidity
modifier isSolvent(address _borrower)
```

在执行合约代码后检查偿还能力。

| Param      | Type    | Description                               |
| ---------- | ------- | ----------------------------------------- |
| \_borrower | address | The borrower whose solvency we will check |

### approvedBorrower <a href="#approvedborrower" id="approvedborrower"></a>

```solidity
modifier approvedBorrower()
```

检查 `msg.sender` 是否为已批准的借款人。

### approvedLender <a href="#approvedlender" id="approvedlender"></a>

```solidity
modifier approvedLender(address _receiver)
```

检查 `msg.sender` 和 `_receiver` 是否都是已批准的贷款人。

| Param      | Type    | Description                             |
| ---------- | ------- | --------------------------------------- |
| \_receiver | address | An additional receiver address to check |

### isNotPastMaturity <a href="#isnotpastmaturity" id="isnotpastmaturity"></a>

```solidity
modifier isNotPastMaturity()
```

确保在超过到期日期时不调用该函数。

### AddInterest <a href="#addinterest" id="addinterest"></a>

```solidity
event AddInterest(uint256 _interestEarned, uint256 _rate, uint256 _deltaTime, uint256 _feesAmount, uint256 _feesShare)
```

当借款人累积利息时，发出 `AddInterest` 事件。

| Param            | Type    | Description                                          |
| ---------------- | ------- | ---------------------------------------------------- |
| \_interestEarned | uint256 | The total interest accrued by all borrowers          |
| \_rate           | uint256 | The interest rate used to calculate accrued interest |
| \_deltaTime      | uint256 | The time elapsed since last interest accrual         |
| \_feesAmount     | uint256 | The amount of fees paid to protocol                  |
| \_feesShare      | uint256 | The amount of shares distributed to protocol         |

### UpdateRate <a href="#updaterate" id="updaterate"></a>

```solidity
event UpdateRate(uint256 _ratePerSec, uint256 _deltaTime, uint256 _utilizationRate, uint256 _newRatePerSec)
```

当利率更新时，发出 `UpdateRate` 事件。

| Param             | Type    | Description                           |
| ----------------- | ------- | ------------------------------------- |
| \_ratePerSec      | uint256 | The old interest rate (per second)    |
| \_deltaTime       | uint256 | The time elapsed since last update    |
| \_utilizationRate | uint256 | The utilization of assets in the Pair |
| \_newRatePerSec   | uint256 | The new interest rate (per second)    |

### addInterest <a href="#addinterest-1" id="addinterest-1"></a>

```solidity
function addInterest() external returns (uint256 _interestEarned, uint256 _feesAmount, uint256 _feesShare, uint64 _newRate)
```

`addInterest` 函数是 `_addInterest` 的公共实现，允许第三方触发利息的累积。

| Return           | Type    | Description                                     |
| ---------------- | ------- | ----------------------------------------------- |
| \_interestEarned | uint256 | The amount of interest accrued by all borrowers |
| \_feesAmount     | uint256 |                                                 |
| \_feesShare      | uint256 |                                                 |
| \_newRate        | uint64  |                                                 |

### \_addInterest <a href="#addinterest-2" id="addinterest-2"></a>

```solidity
function _addInterest() internal returns (uint256 _interestEarned, uint256 _feesAmount, uint256 _feesShare, uint64 _newRate)
```

`_addInterest` 函数在每个外部函数调用之前被调用，用于累积利息并更新利率。

*该函数每个区块只能调用一次。*

| Return           | Type    | Description                                     |
| ---------------- | ------- | ----------------------------------------------- |
| \_interestEarned | uint256 | The amount of interest accrued by all borrowers |
| \_feesAmount     | uint256 |                                                 |
| \_feesShare      | uint256 |                                                 |
| \_newRate        | uint64  |                                                 |

### UpdateExchangeRate <a href="#updateexchangerate" id="updateexchangerate"></a>

```solidity
event UpdateExchangeRate(uint256 _rate)
```

当抵押品与资产的汇率更新时，发出 `UpdateExchangeRate` 事件。

| Param  | Type    | Description                                                                  |
| ------ | ------- | ---------------------------------------------------------------------------- |
| \_rate | uint256 | The new rate given as the amount of Collateral Token to buy 1e18 Asset Token |

### updateExchangeRate <a href="#updateexchangerate-1" id="updateexchangerate-1"></a>

```solidity
function updateExchangeRate() external returns (uint256 _exchangeRate)
```

`updateExchangeRate` 函数是 `_updateExchangeRate` 的外部实现。

*由于这些查询可能会很耗费资源，该函数在每个区块中最多只能被调用一次。*

| Return         | Type    | Description           |
| -------------- | ------- | --------------------- |
| \_exchangeRate | uint256 | The new exchange rate |

### \_updateExchangeRate <a href="#updateexchangerate-2" id="updateexchangerate-2"></a>

```solidity
function _updateExchangeRate() internal returns (uint256 _exchangeRate)
```

`_updateExchangeRate` 函数用于获取最新的汇率，即购买 1e18 资产所需的抵押品数量。

*由于这些查询可能会非常耗费资源，该函数在每个区块中最多只能被调用一次。*

| Return         | Type    | Description           |
| -------------- | ------- | --------------------- |
| \_exchangeRate | uint256 | The new exchange rate |

### \_deposit <a href="#deposit" id="deposit"></a>

```solidity
function _deposit(struct VaultAccount _totalAsset, uint128 _amount, uint128 _shares, address _receiver) internal
```

`_deposit` 函数是用于出借资产的内部实现。

*调用者必须在调用该函数之前对资产代币合约调用 `ERC20.approve`。*

| Param        | Type                | Description                                                                                    |
| ------------ | ------------------- | ---------------------------------------------------------------------------------------------- |
| \_totalAsset | struct VaultAccount | An in memory VaultAccount struct representing the total amounts and shares for the Asset Token |
| \_amount     | uint128             | The amount of Asset Token to be transferred                                                    |
| \_shares     | uint128             | The amount of Asset Shares (fTokens) to be minted                                              |
| \_receiver   | address             | The address to receive the Asset Shares (fTokens)                                              |

### deposit <a href="#deposit-1" id="deposit-1"></a>

```solidity
function deposit(uint256 _amount, address _receiver) external returns (uint256 _sharesReceived)
```

`deposit` 函数允许用户通过指定要出借的资产代币数量来出借资产。

*调用者必须在调用该函数之前对资产代币合约调用 `ERC20.approve`。*

| Param      | Type    | Description                                       |
| ---------- | ------- | ------------------------------------------------- |
| \_amount   | uint256 | The amount of Asset Token to transfer to Pair     |
| \_receiver | address | The address to receive the Asset Shares (fTokens) |

| Return           | Type    | Description                                    |
| ---------------- | ------- | ---------------------------------------------- |
| \_sharesReceived | uint256 | The number of fTokens received for the deposit |

### mint <a href="#mint" id="mint"></a>

```solidity
function mint(uint256 _shares, address _receiver) external returns (uint256 _amountReceived)
```

`mint` 函数允许用户通过指定要铸造的资产股份（fTokens）数量来出借资产。

*调用者必须在调用该函数之前对资产代币合约调用 `ERC20.approve`。*

| Param      | Type    | Description                                                    |
| ---------- | ------- | -------------------------------------------------------------- |
| \_shares   | uint256 | The number of Asset Shares (fTokens) that a user wants to mint |
| \_receiver | address | The address to receive the Asset Shares (fTokens)              |

| Return           | Type    | Description                                        |
| ---------------- | ------- | -------------------------------------------------- |
| \_amountReceived | uint256 | The amount of Asset Tokens transferred to the Pair |

### \_redeem <a href="#redeem" id="redeem"></a>

```solidity
function _redeem(struct VaultAccount _totalAsset, uint128 _amountToReturn, uint128 _shares, address _receiver, address _owner) internal
```

`_redeem` 函数是一个内部实现，允许贷款人从交易对中提取他们的资产代币。

*调用者必须在调用该函数之前对资产代币合约调用 `ERC20.approve`。*

| Param            | Type                | Description                                                                                                                  |
| ---------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| \_totalAsset     | struct VaultAccount | An in-memory VaultAccount struct which holds the total amount of Asset Tokens and the total number of Asset Shares (fTokens) |
| \_amountToReturn | uint128             | The number of Asset Tokens to return                                                                                         |
| \_shares         | uint128             | The number of Asset Shares (fTokens) to burn                                                                                 |
| \_receiver       | address             | The address to which the Asset Tokens will be transferred                                                                    |
| \_owner          | address             | The owner of the Asset Shares (fTokens)                                                                                      |

### redeem <a href="#redeem-1" id="redeem-1"></a>

```solidity
function redeem(uint256 _shares, address _receiver, address _owner) external returns (uint256 _amountToReturn)
```

`redeem` 函数允许调用者将他们的资产股份兑换为资产代币。

| Param      | Type    | Description                                                   |
| ---------- | ------- | ------------------------------------------------------------- |
| \_shares   | uint256 | The number of Asset Shares (fTokens) to burn for Asset Tokens |
| \_receiver | address | The address to which the Asset Tokens will be transferred     |
| \_owner    | address | The owner of the Asset Shares (fTokens)                       |

| Return           | Type    | Description                                  |
| ---------------- | ------- | -------------------------------------------- |
| \_amountToReturn | uint256 | The amount of Asset Tokens to be transferred |

### withdraw <a href="#withdraw" id="withdraw"></a>

```solidity
function withdraw(uint256 _amount, address _receiver, address _owner) external returns (uint256 _shares)
```

`withdraw` 函数允许用户将他们的资产股份兑换为指定数量的资产代币。

| Param      | Type    | Description                                                                       |
| ---------- | ------- | --------------------------------------------------------------------------------- |
| \_amount   | uint256 | The amount of Asset Tokens to be transferred in exchange for burning Asset Shares |
| \_receiver | address | The address to which the Asset Tokens will be transferred                         |
| \_owner    | address | The owner of the Asset Shares (fTokens)                                           |

| Return   | Type    | Description                                 |
| -------- | ------- | ------------------------------------------- |
| \_shares | uint256 | The number of Asset Shares (fTokens) burned |

### BorrowAsset <a href="#borrowasset" id="borrowasset"></a>

```solidity
event BorrowAsset(address _borrower, address _receiver, uint256 _borrowAmount, uint256 _sharesAdded)
```

当借款人增加其头寸时，发出 `BorrowAsset` 事件。

| Param          | Type    | Description                                            |
| -------------- | ------- | ------------------------------------------------------ |
| \_borrower     | address | The borrower whose account was debited                 |
| \_receiver     | address | The address to which the Asset Tokens were transferred |
| \_borrowAmount | uint256 | The amount of Asset Tokens transferred                 |
| \_sharesAdded  | uint256 | The number of Borrow Shares the borrower was debited   |

### \_borrowAsset <a href="#borrowasset-1" id="borrowasset-1"></a>

```solidity
function _borrowAsset(uint128 _borrowAmount, address _receiver) internal returns (uint256 _sharesAdded)
```

`_borrowAsset` 函数是借款资产的内部实现。

| Param          | Type    | Description                             |
| -------------- | ------- | --------------------------------------- |
| \_borrowAmount | uint128 | The amount of the Asset Token to borrow |
| \_receiver     | address | The address to receive the Asset Tokens |

| Return        | Type    | Description                                                |
| ------------- | ------- | ---------------------------------------------------------- |
| \_sharesAdded | uint256 | The amount of borrow shares the msg.sender will be debited |

### borrowAsset <a href="#borrowasset-2" id="borrowasset-2"></a>

```solidity
function borrowAsset(uint256 _borrowAmount, uint256 _collateralAmount, address _receiver) external returns (uint256 _shares)
```

`borrowAsset` 函数允许用户开立或增加借款头寸。

*如果适用，借款人必须在调用该函数之前对抵押代币合约调用 `ERC20.approve`。*

| Param              | Type    | Description                                        |
| ------------------ | ------- | -------------------------------------------------- |
| \_borrowAmount     | uint256 | The amount of Asset Token to borrow                |
| \_collateralAmount | uint256 | The amount of Collateral Token to transfer to Pair |
| \_receiver         | address | The address which will receive the Asset Tokens    |

| Return   | Type    | Description                                                |
| -------- | ------- | ---------------------------------------------------------- |
| \_shares | uint256 | The number of borrow Shares the msg.sender will be debited |

### \_addCollateral <a href="#addcollateral" id="addcollateral"></a>

```solidity
function _addCollateral(address _sender, uint256 _collateralAmount, address _borrower) internal
```

`_addCollateral` 函数是向借款人头寸添加抵押品的内部实现。

| Param              | Type    | Description                                                      |
| ------------------ | ------- | ---------------------------------------------------------------- |
| \_sender           | address | The source of funds for the new collateral                       |
| \_collateralAmount | uint256 | The amount of Collateral Token to be transferred                 |
| \_borrower         | address | The borrower account for which the collateral should be credited |

### addCollateral <a href="#addcollateral-1" id="addcollateral-1"></a>

```solidity
function addCollateral(uint256 _collateralAmount, address _borrower) external
```

`addCollateral` 函数允许调用者向借款人头寸添加抵押代币。

*`msg.sender` 必须在调用该函数之前对抵押代币合约调用 `ERC20.approve()`。*

| Param              | Type    | Description                                                       |
| ------------------ | ------- | ----------------------------------------------------------------- |
| \_collateralAmount | uint256 | The amount of Collateral Token to be added to borrower's position |
| \_borrower         | address | The account to be credited                                        |

### RemoveCollateral <a href="#removecollateral" id="removecollateral"></a>

```solidity
event RemoveCollateral(address _sender, uint256 _collateralAmount, address _receiver, address _borrower)
```

当抵押品从借款人的头寸中移除时，发出 `RemoveCollateral` 事件。

| Param              | Type    | Description                                                |
| ------------------ | ------- | ---------------------------------------------------------- |
| \_sender           | address | The account from which funds are transferred               |
| \_collateralAmount | uint256 | The amount of Collateral Token to be transferred           |
| \_receiver         | address | The address to which Collateral Tokens will be transferred |
| \_borrower         | address |                                                            |

### \_removeCollateral <a href="#removecollateral-1" id="removecollateral-1"></a>

```solidity
function _removeCollateral(uint256 _collateralAmount, address _receiver, address _borrower) internal
```

`_removeCollateral` 函数是从借款人头寸中移除抵押品的内部实现。

| Param              | Type    | Description                                                           |
| ------------------ | ------- | --------------------------------------------------------------------- |
| \_collateralAmount | uint256 | The amount of Collateral Token to remove from the borrower's position |
| \_receiver         | address | The address to receive the Collateral Token transferred               |
| \_borrower         | address | The borrower whose account will be debited the Collateral amount      |

### removeCollateral <a href="#removecollateral-2" id="removecollateral-2"></a>

```solidity
function removeCollateral(uint256 _collateralAmount, address _receiver) external
```

`removeCollateral` 函数用于从 `msg.sender` 的借款头寸中移除抵押品。

*调用后，`msg.sender` 必须保持偿付能力，否则交易将会回退。*

| Param              | Type    | Description                                  |
| ------------------ | ------- | -------------------------------------------- |
| \_collateralAmount | uint256 | The amount of Collateral Token to transfer   |
| \_receiver         | address | The address to receive the transferred funds |

### RepayAsset <a href="#repayasset" id="repayasset"></a>

```solidity
event RepayAsset(address _sender, address _borrower, uint256 _amountToRepay, uint256 _shares)
```

每当债务头寸被偿还时，发出 `RepayAsset` 事件。

| Param           | Type    | Description                                                                         |
| --------------- | ------- | ----------------------------------------------------------------------------------- |
| \_sender        | address | The msg.sender of the transaction                                                   |
| \_borrower      | address | The borrower whose account will be credited                                         |
| \_amountToRepay | uint256 | The amount of Asset token to be transferred                                         |
| \_shares        | uint256 | The amount of Borrow Shares which will be debited from the borrower after repayment |

### \_repayAsset <a href="#repayasset-1" id="repayasset-1"></a>

```solidity
function _repayAsset(struct VaultAccount _totalBorrow, uint128 _amountToRepay, uint128 _shares, address _payer, address _borrower) internal
```

`_repayAsset` 函数是偿还借款头寸的内部实现。

*付款人必须在调用该函数之前对资产代币合约调用 `ERC20.approve()`。*

| Param           | Type                | Description                                              |
| --------------- | ------------------- | -------------------------------------------------------- |
| \_totalBorrow   | struct VaultAccount | An in memory copy of the totalBorrow VaultAccount struct |
| \_amountToRepay | uint128             | The amount of Asset Token to transfer                    |
| \_shares        | uint128             | The number of Borrow Shares the sender is repaying       |
| \_payer         | address             | The address from which funds will be transferred         |
| \_borrower      | address             | The borrower account which will be credited              |

### repayAsset <a href="#repayasset-2" id="repayasset-2"></a>

```solidity
function repayAsset(uint256 _shares, address _borrower) external returns (uint256 _amountToRepay)
```

`repayAsset` 函数允许调用者偿还特定借款人的债务。

*调用者必须首先对资产代币合约调用 `ERC20.approve()`。*

| Param      | Type    | Description                                                  |
| ---------- | ------- | ------------------------------------------------------------ |
| \_shares   | uint256 | The number of Borrow Shares which will be repaid by the call |
| \_borrower | address | The account for which the debt will be reduced               |

| Return          | Type    | Description                                                                           |
| --------------- | ------- | ------------------------------------------------------------------------------------- |
| \_amountToRepay | uint256 | The amount of Asset Tokens which were transferred in order to repay the Borrow Shares |

### Liquidate <a href="#liquidate" id="liquidate"></a>

```solidity
event Liquidate(address _borrower, uint256 _collateralForLiquidator, uint256 _shares)
```

当发生清算时，发出 `Liquidate` 事件。

| Param                     | Type    | Description                                                                 |
| ------------------------- | ------- | --------------------------------------------------------------------------- |
| \_borrower                | address | The borrower account for which the liquidation occured                      |
| \_collateralForLiquidator | uint256 | The amount of Collateral Token transferred to the liquidator                |
| \_shares                  | uint256 | The number of Borrow Shares the liquidator repaid on behalf of the borrower |

### liquidate <a href="#liquidate-1" id="liquidate-1"></a>

```solidity
function liquidate(uint256 _shares, address _borrower) external returns (uint256 _collateralForLiquidator)
```

`liquidate` 函数允许第三方偿还已成为不偿还能力的借款人的债务。

*调用者必须在调用 `Liquidate()` 之前对资产代币合约调用 `ERC20.approve`。*

| Param      | Type    | Description                                                                            |
| ---------- | ------- | -------------------------------------------------------------------------------------- |
| \_shares   | uint256 | The number of Borrow Shares repaid by the liquidator                                   |
| \_borrower | address | The account for which the repayment is credited and from whom collateral will be taken |

| Return                    | Type    | Description                                                  |
| ------------------------- | ------- | ------------------------------------------------------------ |
| \_collateralForLiquidator | uint256 | The amount of Collateral Token transferred to the liquidator |

### LeveragedPosition <a href="#leveragedposition" id="leveragedposition"></a>

```solidity
event LeveragedPosition(address _borrower, address _swapperAddress, uint256 _borrowAmount, uint256 _borrowShares, uint256 _initialCollateralAmount, uint256 _amountCollateralOut)
```

当借款人开立新的杠杆头寸时，发出 `LeveragedPosition` 事件。

| Param                     | Type    | Description                                                            |
| ------------------------- | ------- | ---------------------------------------------------------------------- |
| \_borrower                | address | The account for which the debt is debited                              |
| \_swapperAddress          | address | The address of the swapper which conforms the FraxSwap interface       |
| \_borrowAmount            | uint256 | The amount of Asset Token to be borrowed to be borrowed                |
| \_borrowShares            | uint256 | The number of Borrow Shares the borrower is credited                   |
| \_initialCollateralAmount | uint256 | The amount of initial Collateral Tokens supplied by the borrower       |
| \_amountCollateralOut     | uint256 | The amount of Collateral Token which was received for the Asset Tokens |

### leveragedPosition <a href="#leveragedposition-1" id="leveragedposition-1"></a>

```solidity
function leveragedPosition(address _swapperAddress, uint256 _borrowAmount, uint256 _initialCollateralAmount, uint256 _amountCollateralOutMin, address[] _path) external returns (uint256 _totalCollateralBalance)
```

`leveragedPosition` 函数允许用户以最小的前期抵押品进入杠杆借款头寸。

*调用者必须在调用该函数之前对抵押代币合约调用 `ERC20.approve()`。*

| Param                     | Type       | Description                                                                                       |
| ------------------------- | ---------- | ------------------------------------------------------------------------------------------------- |
| \_swapperAddress          | address    | The address of the whitelisted swapper to use to swap borrowed Asset Tokens for Collateral Tokens |
| \_borrowAmount            | uint256    | The amount of Asset Tokens borrowed                                                               |
| \_initialCollateralAmount | uint256    | The initial amount of Collateral Tokens supplied by the borrower                                  |
| \_amountCollateralOutMin  | uint256    | The minimum amount of Collateral Tokens to be received in exchange for the borrowed Asset Tokens  |
| \_path                    | address\[] | An array containing the addresses of ERC20 tokens to swap. Adheres to UniV2 style path params.    |

| Return                   | Type    | Description                                                                     |
| ------------------------ | ------- | ------------------------------------------------------------------------------- |
| \_totalCollateralBalance | uint256 | The total amount of Collateral Tokens added to a users account (initial + swap) |

### RepayAssetWithCollateral <a href="#repayassetwithcollateral" id="repayassetwithcollateral"></a>

```solidity
event RepayAssetWithCollateral(address _borrower, address _swapperAddress, uint256 _collateralToSwap, uint256 _amountAssetOut, uint256 _sharesRepaid)
```

每当调用 `repayAssetWithCollateral()` 时，发出 `RepayAssetWithCollateral` 事件。

| Param              | Type    | Description                                                   |
| ------------------ | ------- | ------------------------------------------------------------- |
| \_borrower         | address | The borrower account for which the repayment is taking place  |
| \_swapperAddress   | address | The address of the whitelisted swapper to use for token swaps |
| \_collateralToSwap | uint256 | The amount of Collateral Token to swap and use for repayment  |
| \_amountAssetOut   | uint256 | The amount of Asset Token which was repaid                    |
| \_sharesRepaid     | uint256 | The number of Borrow Shares which were repaid                 |

### repayAssetWithCollateral <a href="#repayassetwithcollateral-1" id="repayassetwithcollateral-1"></a>

```solidity
function repayAssetWithCollateral(address _swapperAddress, uint256 _collateralToSwap, uint256 _amountAssetOutMin, address[] _path) external returns (uint256 _amountAssetOut)
```

`repayAssetWithCollateral` 函数允许借款人使用合约中现有的抵押品偿还其债务。

| Param               | Type       | Description                                                                                    |
| ------------------- | ---------- | ---------------------------------------------------------------------------------------------- |
| \_swapperAddress    | address    | The address of the whitelisted swapper to use for token swaps                                  |
| \_collateralToSwap  | uint256    | The amount of Collateral Tokens to swap for Asset Tokens                                       |
| \_amountAssetOutMin | uint256    | The minimum amount of Asset Tokens to receive during the swap                                  |
| \_path              | address\[] | An array containing the addresses of ERC20 tokens to swap. Adheres to UniV2 style path params. |

| Return           | Type    | Description                                                                                                  |
| ---------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| \_amountAssetOut | uint256 | The amount of Asset Tokens received for the Collateral Tokens, the amount the borrowers account was credited |
