> For the complete documentation index, see [llms.txt](https://docs.3adao.org/3a-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.3adao.org/3a-protocol/technical-documentation/smart-contracts/interacting-with-contracts/borrowing-and-repaying.md).

# Borrowing and Repaying

The `vaultOwner()` has the right to borrow from its own vaults, \
provided they have enough collateral to do it.\
\
Borrow will effectively mint EURO3, thus adding more circulating supply.\
To get `IVault` interface, refer to [Creating a vault](/3a-protocol/technical-documentation/smart-contracts/interacting-with-contracts/creating-a-vault.md)\
\
Here's an example of a simple borrowing interaction:

```solidity
import "./IVaultFactory.sol";
import "./IVault.sol";
import "./ERC20.sol";


// --- core contract logic ---
IVaultFactory vaultFactory = IVaultFactory(0x.....0);
address vaultAddress = 0x...0;
address destinationAddress = msg.sender;

IVault myVault = IVault(vaultAddress);


// get the maximum amount you can borrow
(uint256 maxBorrowable, ) = myVault.borrowable();

// borrowing can only be done from the VaultFactory
vaultFactory.borrow(vaultAddress, maxBorrowable, destinationAddress);

// healthFactor is 18 decimals,
// meaning 1e18 = 1.0 HF
uint256 healthFactor = myVault.healthFactor(false);

require(healthFactor > 2 ** 1e18, "borrowed too much!");
```

***

### Repaying your loan

Repaying a loan requires enough EURO3 is approved to be spent by the `VaultFactory`\
Here's an example implementation:

```solidity
import "./IVaultFactory.sol";
import "./IVault.sol";
import "./ERC20.sol";


// --- core contract logic ---
IVaultFactory vaultFactory = IVaultFactory(0x.....0);
address vaultAddress = 0x...0;

IVault myVault = IVault(vaultAddress);

IERC20 euro3 = IERC20(vaultFactory.stable());

uint256 vaultDebt = myVault.debt();
uint256 euro3Balance = euro3.balanceOf(address(this));

euro3.approve(vaultDebt, vaultDebt);

require(euro3Balance >= vaultDebt, "not enough fund to repay fully");

VaultFactory.repay(vaultAddress, vaultDebt);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.3adao.org/3a-protocol/technical-documentation/smart-contracts/interacting-with-contracts/borrowing-and-repaying.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
