# Solidity API

## LiquidationAuction02

#### vault

```solidity
contract IVault vault
```

#### vaultManagerParameters

```solidity
contract IVaultManagerParameters vaultManagerParameters
```

#### cdpRegistry

```solidity
contract ICDPRegistry cdpRegistry
```

#### forceTransferAssetStore

```solidity
contract IForceTransferAssetStore forceTransferAssetStore
```

#### DENOMINATOR\_1E2

```solidity
uint256 DENOMINATOR_1E2
```

#### WRAPPED\_TO\_UNDERLYING\_ORACLE\_TYPE

```solidity
uint256 WRAPPED_TO_UNDERLYING_ORACLE_TYPE
```

#### Buyout

```solidity
event Buyout(address asset, address owner, address buyer, uint256 amount, uint256 price, uint256 penalty)
```

*Trigger when buyouts are happened*

#### checkpoint

```solidity
modifier checkpoint(address asset, address owner)
```

#### constructor

```solidity
constructor(address _vaultManagerParameters, address _cdpRegistry, address _forceTransferAssetStore) public
```

| Name                      | Type    | Description                                               |
| ------------------------- | ------- | --------------------------------------------------------- |
| \_vaultManagerParameters  | address | The address of the contract with Vault manager parameters |
| \_cdpRegistry             | address | The address of the CDP registry                           |
| \_forceTransferAssetStore | address | The address of the ForceTransferAssetStore                |

#### buyout

```solidity
function buyout(address asset, address owner) public
```

*Buyouts a position's collateral*

| Name  | Type    | Description                                            |
| ----- | ------- | ------------------------------------------------------ |
| asset | address | The address of the main collateral token of a position |
| owner | address | The owner of a position                                |

#### \_liquidate

```solidity
function _liquidate(address asset, address user, uint256 collateralToBuyer, uint256 collateralToOwner, uint256 repayment, uint256 penalty) private
```

#### \_calcLiquidationParams

```solidity
function _calcLiquidationParams(uint256 depreciationPeriod, uint256 blocksPast, uint256 startingPrice, uint256 debtWithPenalty, uint256 collateralInPosition) internal pure returns (uint256 collateralToBuyer, uint256 collateralToOwner, uint256 price)
```

## CDPRegistry

#### CDP

```solidity
struct CDP {
  address asset;
  address owner;
}
```

#### cdpList

```solidity
mapping(address => address[]) cdpList
```

#### cdpIndex

```solidity
mapping(address => mapping(address => uint256)) cdpIndex
```

#### vault

```solidity
contract IVault vault
```

#### cr

```solidity
contract ICollateralRegistry cr
```

#### Added

```solidity
event Added(address asset, address owner)
```

#### Removed

```solidity
event Removed(address asset, address owner)
```

#### constructor

```solidity
constructor(address _vault, address _collateralRegistry) public
```

#### checkpoint

```solidity
function checkpoint(address asset, address owner) public
```

#### batchCheckpointForAsset

```solidity
function batchCheckpointForAsset(address asset, address[] owners) external
```

#### batchCheckpoint

```solidity
function batchCheckpoint(address[] assets, address[] owners) external
```

#### isAlive

```solidity
function isAlive(address asset, address owner) public view returns (bool)
```

#### isListed

```solidity
function isListed(address asset, address owner) public view returns (bool)
```

#### \_removeCdp

```solidity
function _removeCdp(address asset, address owner) internal
```

#### \_addCdp

```solidity
function _addCdp(address asset, address owner) internal
```

#### getCdpsByCollateral

```solidity
function getCdpsByCollateral(address asset) external view returns (struct CDPRegistry.CDP[] cdps)
```

#### getCdpsByOwner

```solidity
function getCdpsByOwner(address owner) external view returns (struct CDPRegistry.CDP[] r)
```

#### getAllCdps

```solidity
function getAllCdps() external view returns (struct CDPRegistry.CDP[] r)
```

#### getCdpsCount

```solidity
function getCdpsCount() public view returns (uint256 totalCdpCount)
```

#### getCdpsCountForCollateral

```solidity
function getCdpsCountForCollateral(address asset) public view returns (uint256)
```

## CollateralRegistry

#### CollateralAdded

```solidity
event CollateralAdded(address asset)
```

#### CollateralRemoved

```solidity
event CollateralRemoved(address asset)
```

#### collateralId

```solidity
mapping(address => uint256) collateralId
```

#### collateralList

```solidity
address[] collateralList
```

#### constructor

```solidity
constructor(address _vaultParameters, address[] assets) public
```

#### addCollateral

```solidity
function addCollateral(address asset) public
```

#### removeCollateral

```solidity
function removeCollateral(address asset) public
```

#### isCollateral

```solidity
function isCollateral(address asset) public view returns (bool)
```

#### collaterals

```solidity
function collaterals() external view returns (address[])
```

#### collateralsCount

```solidity
function collateralsCount() external view returns (uint256)
```

## GCD

*ERC20 token*

#### name

```solidity
string name
```

#### symbol

```solidity
string symbol
```

#### version

```solidity
string version
```

#### decimals

```solidity
uint8 decimals
```

#### totalSupply

```solidity
uint256 totalSupply
```

#### balanceOf

```solidity
mapping(address => uint256) balanceOf
```

#### allowance

```solidity
mapping(address => mapping(address => uint256)) allowance
```

#### Approval

```solidity
event Approval(address owner, address spender, uint256 value)
```

*Trigger on any successful call to approve(address spender, uint amount)*

#### Transfer

```solidity
event Transfer(address from, address to, uint256 value)
```

*Trigger when tokens are transferred, including zero value transfers*

#### initialize

```solidity
function initialize(address _parameters) public
```

| Name         | Type    | Description                               |
| ------------ | ------- | ----------------------------------------- |
| \_parameters | address | The address of system parameters contract |

#### \_authorizeUpgrade

```solidity
function _authorizeUpgrade(address) internal
```

Restricted upgrades function

#### mint

```solidity
function mint(address to, uint256 amount) external
```

Only Vault can mint GCD

*Mints 'amount' of tokens to address 'to', and MUST fire the Transfer event*

| Name   | Type    | Description                      |
| ------ | ------- | -------------------------------- |
| to     | address | The address of the recipient     |
| amount | uint256 | The amount of token to be minted |

#### burn

```solidity
function burn(uint256 amount) external
```

Only manager can burn tokens from manager's balance

*Burns 'amount' of tokens, and MUST fire the Transfer event*

| Name   | Type    | Description                      |
| ------ | ------- | -------------------------------- |
| amount | uint256 | The amount of token to be burned |

#### burn

```solidity
function burn(address from, uint256 amount) external
```

Only Vault can burn tokens from any balance

*Burns 'amount' of tokens from 'from' address, and MUST fire the Transfer event*

| Name   | Type    | Description                      |
| ------ | ------- | -------------------------------- |
| from   | address | The address of the balance owner |
| amount | uint256 | The amount of token to be burned |

#### transfer

```solidity
function transfer(address to, uint256 amount) external returns (bool)
```

\_Transfers 'amount' of tokens to address 'to', and MUST fire the Transfer event. The function SHOULD throw if the *from account balance does not have enough tokens to spend.*

| Name   | Type    | Description                           |
| ------ | ------- | ------------------------------------- |
| to     | address | The address of the recipient          |
| amount | uint256 | The amount of token to be transferred |

#### transferFrom

```solidity
function transferFrom(address from, address to, uint256 amount) public returns (bool)
```

*Transfers 'amount' of tokens from address 'from' to address 'to', and MUST fire the Transfer event*

| Name   | Type    | Description                           |
| ------ | ------- | ------------------------------------- |
| from   | address | The address of the sender             |
| to     | address | The address of the recipient          |
| amount | uint256 | The amount of token to be transferred |

#### approve

```solidity
function approve(address spender, uint256 amount) external returns (bool)
```

*Allows 'spender' to withdraw from your account multiple times, up to the 'amount' amount. If this function is called again it overwrites the current allowance with 'amount'.*

| Name    | Type    | Description                                            |
| ------- | ------- | ------------------------------------------------------ |
| spender | address | The address of the account able to transfer the tokens |
| amount  | uint256 | The amount of tokens to be approved for transfer       |

#### increaseAllowance

```solidity
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool)
```

\_Atomically increases the allowance granted to `spender` by the caller.

This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`.

Emits an `Approval` event indicating the updated allowance.

Requirements:

* `spender` cannot be the zero address.\_

#### decreaseAllowance

```solidity
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool)
```

\_Atomically decreases the allowance granted to `spender` by the caller.

This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`.

Emits an `Approval` event indicating the updated allowance.

Requirements:

* `spender` cannot be the zero address.
* `spender` must have allowance for the caller of at least `subtractedValue`.\_

#### \_approve

```solidity
function _approve(address owner, address spender, uint256 amount) internal virtual
```

#### \_burn

```solidity
function _burn(address from, uint256 amount) internal virtual
```

## CDPManager01

#### vault

```solidity
contract IVault vault
```

#### vaultManagerParameters

```solidity
contract IVaultManagerParameters vaultManagerParameters
```

#### oracleRegistry

```solidity
contract IOracleRegistry oracleRegistry
```

#### cdpRegistry

```solidity
contract ICDPRegistry cdpRegistry
```

#### WETH

```solidity
address payable WETH
```

#### Q112

```solidity
uint256 Q112
```

#### DENOMINATOR\_1E5

```solidity
uint256 DENOMINATOR_1E5
```

#### Join

```solidity
event Join(address asset, address owner, uint256 main, uint256 gcd)
```

*Trigger when joins are happened*

#### Exit

```solidity
event Exit(address asset, address owner, uint256 main, uint256 gcd)
```

*Trigger when exits are happened*

#### LiquidationTriggered

```solidity
event LiquidationTriggered(address asset, address owner)
```

*Trigger when liquidations are initiated*

#### checkpoint

```solidity
modifier checkpoint(address asset, address owner)
```

#### constructor

```solidity
constructor(address _vaultManagerParameters, address _oracleRegistry, address _cdpRegistry) public
```

| Name                     | Type    | Description                                               |
| ------------------------ | ------- | --------------------------------------------------------- |
| \_vaultManagerParameters | address | The address of the contract with Vault manager parameters |
| \_oracleRegistry         | address | The address of the oracle registry                        |
| \_cdpRegistry            | address | The address of the CDP registry                           |

#### receive

```solidity
receive() external payable
```

#### join

```solidity
function join(address asset, uint256 assetAmount, uint256 gcdAmount) public
```

Depositing tokens must be pre-approved to Vault address position actually considered as spawned only when debt > 0

*Deposits collateral and/or borrows GCD*

| Name        | Type    | Description                             |
| ----------- | ------- | --------------------------------------- |
| asset       | address | The address of the collateral           |
| assetAmount | uint256 | The amount of the collateral to deposit |
| gcdAmount   | uint256 | The amount of GCD token to borrow       |

#### join\_Eth

```solidity
function join_Eth(uint256 gcdAmount) external payable
```

*Deposits ETH and/or borrows GCD*

| Name      | Type    | Description                       |
| --------- | ------- | --------------------------------- |
| gcdAmount | uint256 | The amount of GCD token to borrow |

#### exit

```solidity
function exit(address asset, uint256 assetAmount, uint256 gcdAmount) public returns (uint256)
```

Tx sender must have a sufficient GCD balance to pay the debt

*Withdraws collateral and repays specified amount of debt*

| Name        | Type    | Description                              |
| ----------- | ------- | ---------------------------------------- |
| asset       | address | The address of the collateral            |
| assetAmount | uint256 | The amount of the collateral to withdraw |
| gcdAmount   | uint256 | The amount of GCD to repay               |

#### exit\_targetRepayment

```solidity
function exit_targetRepayment(address asset, uint256 assetAmount, uint256 repayment) external returns (uint256)
```

Repayment is the sum of the principal and interest

*Withdraws collateral and repays specified amount of debt*

| Name        | Type    | Description                              |
| ----------- | ------- | ---------------------------------------- |
| asset       | address | The address of the collateral            |
| assetAmount | uint256 | The amount of the collateral to withdraw |
| repayment   | uint256 | The target repayment amount              |

#### exit\_Eth

```solidity
function exit_Eth(uint256 ethAmount, uint256 gcdAmount) public returns (uint256)
```

Withdraws WETH and converts to ETH

| Name      | Type    | Description                      |
| --------- | ------- | -------------------------------- |
| ethAmount | uint256 | ETH amount to withdraw           |
| gcdAmount | uint256 | The amount of GCD token to repay |

#### exit\_Eth\_targetRepayment

```solidity
function exit_Eth_targetRepayment(uint256 ethAmount, uint256 repayment) external returns (uint256)
```

Repayment is the sum of the principal and interest&#x20;

Withdraws WETH and converts to ETH

| Name      | Type    | Description                 |
| --------- | ------- | --------------------------- |
| ethAmount | uint256 | ETH amount to withdraw      |
| repayment | uint256 | The target repayment amount |

#### \_repay

```solidity
function _repay(address asset, address owner, uint256 gcdAmount) internal
```

#### \_ensurePositionCollateralization

```solidity
function _ensurePositionCollateralization(address asset, address owner) internal view
```

#### triggerLiquidation

```solidity
function triggerLiquidation(address asset, address owner) external
```

*Triggers liquidation of a position*

| Name  | Type    | Description                                       |
| ----- | ------- | ------------------------------------------------- |
| asset | address | The address of the collateral token of a position |
| owner | address | The owner of the position                         |

#### getCollateralUsdValue\_q112

```solidity
function getCollateralUsdValue_q112(address asset, address owner) public view returns (uint256)
```

#### \_isLiquidatablePosition

```solidity
function _isLiquidatablePosition(address asset, address owner, uint256 usdValue_q112) internal view returns (bool)
```

*Determines whether a position is liquidatable*

| Name           | Type    | Description                              |
| -------------- | ------- | ---------------------------------------- |
| asset          | address | The address of the collateral            |
| owner          | address | The owner of the position                |
| usdValue\_q112 | uint256 | Q112-encoded USD value of the collateral |

| Name | Type | Description                                       |
| ---- | ---- | ------------------------------------------------- |
| \[0] | bool | boolean value, whether a position is liquidatable |

#### \_ensureOracle

```solidity
function _ensureOracle(address asset) internal view
```

#### isLiquidatablePosition

```solidity
function isLiquidatablePosition(address asset, address owner) public view returns (bool)
```

*Determines whether a position is liquidatable*

| Name  | Type    | Description                   |
| ----- | ------- | ----------------------------- |
| asset | address | The address of the collateral |
| owner | address | The owner of the position     |

| Name | Type | Description                                       |
| ---- | ---- | ------------------------------------------------- |
| \[0] | bool | boolean value, whether a position is liquidatable |

#### utilizationRatio

```solidity
function utilizationRatio(address asset, address owner) public view returns (uint256)
```

*Calculates current utilization ratio*

| Name  | Type    | Description                   |
| ----- | ------- | ----------------------------- |
| asset | address | The address of the collateral |
| owner | address | The owner of the position     |

| Name | Type    | Description       |
| ---- | ------- | ----------------- |
| \[0] | uint256 | utilization ratio |

#### liquidationPrice\_q112

```solidity
function liquidationPrice_q112(address asset, address owner) external view returns (uint256)
```

*Calculates liquidation price*

| Name  | Type    | Description                   |
| ----- | ------- | ----------------------------- |
| asset | address | The address of the collateral |
| owner | address | The owner of the position     |

| Name | Type    | Description                    |
| ---- | ------- | ------------------------------ |
| \[0] | uint256 | Q112-encoded liquidation price |

#### \_calcPrincipal

```solidity
function _calcPrincipal(address asset, address owner, uint256 repayment) internal view returns (uint256)
```

## VaultManagerParameters

#### initialCollateralRatio

```solidity
mapping(address => uint256) initialCollateralRatio
```

#### liquidationRatio

```solidity
mapping(address => uint256) liquidationRatio
```

#### liquidationDiscount

```solidity
mapping(address => uint256) liquidationDiscount
```

#### devaluationPeriod

```solidity
mapping(address => uint256) devaluationPeriod
```

#### constructor

```solidity
constructor(address _vaultParameters) public
```

#### setCollateral

```solidity
function setCollateral(address asset, uint256 stabilityFeeValue, uint256 liquidationFeeValue, uint256 initialCollateralRatioValue, uint256 liquidationRatioValue, uint256 liquidationDiscountValue, uint256 devaluationPeriodValue, uint256 gcdLimit, uint256[] oracles) external
```

Only manager is able to call this function

*Sets ability to use token as the main collateral*

| Name                        | Type       | Description                                           |
| --------------------------- | ---------- | ----------------------------------------------------- |
| asset                       | address    | The address of the main collateral token              |
| stabilityFeeValue           | uint256    | The percentage of the year stability fee (3 decimals) |
| liquidationFeeValue         | uint256    | The liquidation fee percentage (0 decimals)           |
| initialCollateralRatioValue | uint256    | The initial collateralization ratio                   |
| liquidationRatioValue       | uint256    | The liquidation ratio                                 |
| liquidationDiscountValue    | uint256    | The liquidation discount (3 decimals)                 |
| devaluationPeriodValue      | uint256    | The devaluation period in blocks                      |
| gcdLimit                    | uint256    | The GCD token issue limit                             |
| oracles                     | uint256\[] | The enabled oracles type IDs                          |

#### setInitialCollateralRatio

```solidity
function setInitialCollateralRatio(address asset, uint256 newValue) public
```

Only manager is able to call this function

*Sets the initial collateral ratio*

| Name     | Type    | Description                              |
| -------- | ------- | ---------------------------------------- |
| asset    | address | The address of the main collateral token |
| newValue | uint256 | The collateralization ratio (0 decimals) |

#### setLiquidationRatio

```solidity
function setLiquidationRatio(address asset, uint256 newValue) public
```

Only manager is able to call this function

*Sets the liquidation ratio*

| Name     | Type    | Description                              |
| -------- | ------- | ---------------------------------------- |
| asset    | address | The address of the main collateral token |
| newValue | uint256 | The liquidation ratio (0 decimals)       |

#### setLiquidationDiscount

```solidity
function setLiquidationDiscount(address asset, uint256 newValue) public
```

Only manager is able to call this function

*Sets the liquidation discount*

| Name     | Type    | Description                              |
| -------- | ------- | ---------------------------------------- |
| asset    | address | The address of the main collateral token |
| newValue | uint256 | The liquidation discount (3 decimals)    |

#### setDevaluationPeriod

```solidity
function setDevaluationPeriod(address asset, uint256 newValue) public
```

Only manager is able to call this function

*Sets the devaluation period of collateral after liquidation*

| Name     | Type    | Description                              |
| -------- | ------- | ---------------------------------------- |
| asset    | address | The address of the main collateral token |
| newValue | uint256 | The devaluation period in blocks         |

## Vault

Vault is the core of GCD Protocol GCD Stablecoin system&#x20;

Vault stores and manages collateral funds of all positions and counts debts&#x20;

Only Vault can manage supply of GCD token&#x20;

Vault will not be changed/upgraded after initial deployment for the current stablecoin version

#### weth

```solidity
address payable weth
```

#### DENOMINATOR\_1E5

```solidity
uint256 DENOMINATOR_1E5
```

#### DENOMINATOR\_1E2

```solidity
uint256 DENOMINATOR_1E2
```

#### gcd

```solidity
address gcd
```

#### collaterals

```solidity
mapping(address => mapping(address => uint256)) collaterals
```

#### debts

```solidity
mapping(address => mapping(address => uint256)) debts
```

#### liquidationBlock

```solidity
mapping(address => mapping(address => uint256)) liquidationBlock
```

#### liquidationPrice

```solidity
mapping(address => mapping(address => uint256)) liquidationPrice
```

#### tokenDebts

```solidity
mapping(address => uint256) tokenDebts
```

#### stabilityFee

```solidity
mapping(address => mapping(address => uint256)) stabilityFee
```

#### liquidationFee

```solidity
mapping(address => mapping(address => uint256)) liquidationFee
```

#### oracleType

```solidity
mapping(address => mapping(address => uint256)) oracleType
```

#### lastUpdate

```solidity
mapping(address => mapping(address => uint256)) lastUpdate
```

#### notLiquidating

```solidity
modifier notLiquidating(address asset, address user)
```

#### initialize

```solidity
function initialize(address _parameters, address _gcd, address payable _weth) public
```

| Name         | Type            | Description                          |
| ------------ | --------------- | ------------------------------------ |
| \_parameters | address         | The address of the system parameters |
| \_gcd        | address         | GCD token address                    |
| \_weth       | address payable |                                      |

#### \_authorizeUpgrade

```solidity
function _authorizeUpgrade(address) internal
```

Restricted upgrades function

#### receive

```solidity
receive() external payable
```

#### update

```solidity
function update(address asset, address user) public
```

*Updates parameters of the position to the current ones*

| Name  | Type    | Description                              |
| ----- | ------- | ---------------------------------------- |
| asset | address | The address of the main collateral token |
| user  | address | The owner of a position                  |

#### spawn

```solidity
function spawn(address asset, address user, uint256 _oracleType) external
```

*Creates new position for user*

| Name         | Type    | Description                              |
| ------------ | ------- | ---------------------------------------- |
| asset        | address | The address of the main collateral token |
| user         | address | The address of a position's owner        |
| \_oracleType | uint256 | The type of an oracle                    |

#### destroy

```solidity
function destroy(address asset, address user) public
```

*Clears unused storage variables*

| Name  | Type    | Description                              |
| ----- | ------- | ---------------------------------------- |
| asset | address | The address of the main collateral token |
| user  | address | The address of a position's owner        |

#### depositMain

```solidity
function depositMain(address asset, address user, uint256 amount) external
```

Tokens must be pre-approved

*Adds main collateral to a position*

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| asset  | address | The address of the main collateral token |
| user   | address | The address of a position's owner        |
| amount | uint256 | The amount of tokens to deposit          |

#### depositEth

```solidity
function depositEth(address user) external payable
```

*Converts ETH to WETH and adds main collateral to a position*

| Name | Type    | Description                       |
| ---- | ------- | --------------------------------- |
| user | address | The address of a position's owner |

#### withdrawMain

```solidity
function withdrawMain(address asset, address user, uint256 amount) external
```

*Withdraws main collateral from a position*

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| asset  | address | The address of the main collateral token |
| user   | address | The address of a position's owner        |
| amount | uint256 | The amount of tokens to withdraw         |

#### withdrawEth

```solidity
function withdrawEth(address payable user, uint256 amount) external
```

*Withdraws WETH collateral from a position converting WETH to ETH*

| Name   | Type            | Description                       |
| ------ | --------------- | --------------------------------- |
| user   | address payable | The address of a position's owner |
| amount | uint256         | The amount of ETH to withdraw     |

#### borrow

```solidity
function borrow(address asset, address user, uint256 amount) external returns (uint256)
```

*Increases position's debt and mints GCD token*

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| asset  | address | The address of the main collateral token |
| user   | address | The address of a position's owner        |
| amount | uint256 | The amount of GCD to borrow              |

#### repay

```solidity
function repay(address asset, address user, uint256 amount) external returns (uint256)
```

*Decreases position's debt and burns GCD token*

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| asset  | address | The address of the main collateral token |
| user   | address | The address of a position's owner        |
| amount | uint256 | The amount of GCD to repay               |

| Name | Type    | Description                |
| ---- | ------- | -------------------------- |
| \[0] | uint256 | updated debt of a position |

#### chargeFee

```solidity
function chargeFee(address asset, address user, uint256 amount) external
```

*Transfers fee to foundation*

| Name   | Type    | Description                        |
| ------ | ------- | ---------------------------------- |
| asset  | address | The address of the fee asset       |
| user   | address | The address to transfer funds from |
| amount | uint256 | The amount of asset to transfer    |

#### triggerLiquidation

```solidity
function triggerLiquidation(address asset, address positionOwner, uint256 initialPrice) external
```

*Deletes position and transfers collateral to liquidation system*

| Name          | Type    | Description                              |
| ------------- | ------- | ---------------------------------------- |
| asset         | address | The address of the main collateral token |
| positionOwner | address | The address of a position's owner        |
| initialPrice  | uint256 | The starting price of collateral in GCD  |

#### liquidate

```solidity
function liquidate(address asset, address positionOwner, uint256 mainAssetToLiquidator, uint256 mainAssetToPositionOwner, uint256 repayment, uint256 penalty, address liquidator) external
```

*Internal liquidation process*

| Name                     | Type    | Description                                          |
| ------------------------ | ------- | ---------------------------------------------------- |
| asset                    | address | The address of the main collateral token             |
| positionOwner            | address | The address of a position's owner                    |
| mainAssetToLiquidator    | uint256 | The amount of main asset to send to a liquidator     |
| mainAssetToPositionOwner | uint256 | The amount of main asset to send to a position owner |
| repayment                | uint256 | The repayment in GCD                                 |
| penalty                  | uint256 | The liquidation penalty in GCD                       |
| liquidator               | address | The address of a liquidator                          |

#### changeOracleType

```solidity
function changeOracleType(address asset, address user, uint256 newOracleType) external
```

Only manager can call this function

*Changes broken oracle type to the correct one*

| Name          | Type    | Description                              |
| ------------- | ------- | ---------------------------------------- |
| asset         | address | The address of the main collateral token |
| user          | address | The address of a position's owner        |
| newOracleType | uint256 | The new type of an oracle                |

#### getTotalDebt

```solidity
function getTotalDebt(address asset, address user) public view returns (uint256)
```

*Calculates the total amount of position's debt based on elapsed time*

| Name  | Type    | Description                              |
| ----- | ------- | ---------------------------------------- |
| asset | address | The address of the main collateral token |
| user  | address | The address of a position's owner        |

| Name | Type    | Description                                  |
| ---- | ------- | -------------------------------------------- |
| \[0] | uint256 | user debt of a position plus accumulated fee |

#### calculateFee

```solidity
function calculateFee(address asset, address user, uint256 amount) public view returns (uint256)
```

*Calculates the amount of fee based on elapsed time and repayment amount*

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| asset  | address | The address of the main collateral token |
| user   | address | The address of a position's owner        |
| amount | uint256 | The repayment amount                     |

| Name | Type    | Description |
| ---- | ------- | ----------- |
| \[0] | uint256 | fee amount  |

## VaultParameters

#### stabilityFee

```solidity
mapping(address => uint256) stabilityFee
```

#### liquidationFee

```solidity
mapping(address => uint256) liquidationFee
```

#### tokenDebtLimit

```solidity
mapping(address => uint256) tokenDebtLimit
```

#### canModifyVault

```solidity
mapping(address => bool) canModifyVault
```

#### isManager

```solidity
mapping(address => bool) isManager
```

#### isOracleTypeEnabled

```solidity
mapping(uint256 => mapping(address => bool)) isOracleTypeEnabled
```

#### vault

```solidity
address payable vault
```

#### foundation

```solidity
address foundation
```

#### initialize

```solidity
function initialize(address payable _vault, address _foundation) public
```

The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256. Therefore, the Vault address can be pre-computed and passed as an argument before deployment.

#### \_authorizeUpgrade

```solidity
function _authorizeUpgrade(address) internal
```

Restricted upgrades function

#### setManager

```solidity
function setManager(address who, bool permit) external
```

Only manager is able to call this function

*Grants and revokes manager's status of any address*

| Name   | Type    | Description         |
| ------ | ------- | ------------------- |
| who    | address | The target address  |
| permit | bool    | The permission flag |

#### setFoundation

```solidity
function setFoundation(address newFoundation) external
```

Only manager is able to call this function

*Sets the foundation address*

| Name          | Type    | Description                |
| ------------- | ------- | -------------------------- |
| newFoundation | address | The new foundation address |

#### setCollateral

```solidity
function setCollateral(address asset, uint256 stabilityFeeValue, uint256 liquidationFeeValue, uint256 gcdLimit, uint256[] oracles) external
```

Only manager is able to call this function

*Sets ability to use token as the main collateral*

| Name                | Type       | Description                                           |
| ------------------- | ---------- | ----------------------------------------------------- |
| asset               | address    | The address of the main collateral token              |
| stabilityFeeValue   | uint256    | The percentage of the year stability fee (3 decimals) |
| liquidationFeeValue | uint256    | The liquidation fee percentage (0 decimals)           |
| gcdLimit            | uint256    | The GCD token issue limit                             |
| oracles             | uint256\[] | The enables oracle types                              |

#### setVaultAccess

```solidity
function setVaultAccess(address who, bool permit) external
```

Only manager is able to call this function

*Sets a permission for an address to modify the Vault*

| Name   | Type    | Description         |
| ------ | ------- | ------------------- |
| who    | address | The target address  |
| permit | bool    | The permission flag |

#### setStabilityFee

```solidity
function setStabilityFee(address asset, uint256 newValue) public
```

Only manager is able to call this function

*Sets the percentage of the year stability fee for a particular collateral*

| Name     | Type    | Description                               |
| -------- | ------- | ----------------------------------------- |
| asset    | address | The address of the main collateral token  |
| newValue | uint256 | The stability fee percentage (3 decimals) |

#### setLiquidationFee

```solidity
function setLiquidationFee(address asset, uint256 newValue) public
```

Only manager is able to call this function

*Sets the percentage of the liquidation fee for a particular collateral*

| Name     | Type    | Description                                 |
| -------- | ------- | ------------------------------------------- |
| asset    | address | The address of the main collateral token    |
| newValue | uint256 | The liquidation fee percentage (0 decimals) |

#### setOracleType

```solidity
function setOracleType(uint256 _type, address asset, bool enabled) public
```

Only manager is able to call this function

*Enables/disables oracle types*

| Name    | Type    | Description                              |
| ------- | ------- | ---------------------------------------- |
| \_type  | uint256 | The type of the oracle                   |
| asset   | address | The address of the main collateral token |
| enabled | bool    | The control flag                         |

#### setTokenDebtLimit

```solidity
function setTokenDebtLimit(address asset, uint256 limit) public
```

Only manager is able to call this function

*Sets GCD limit for a specific collateral*

| Name  | Type    | Description                              |
| ----- | ------- | ---------------------------------------- |
| asset | address | The address of the main collateral token |
| limit | uint256 | The limit number                         |
