# How to Repay

{% hint style="danger" %}
When repaying take care to input the correct data. Make sure you are repaying for the correct wallet.
{% endhint %}

You can repay any supported asset and close borrow positions across any chain through Replete by interacting with [RepletePool](/contracts/repletepool.md).

Repaying an asset is often straight forward, where you supply the borrowed asset to repay debt positions. However, if interacting with [RepletePool](/contracts/repletepool.md), there are a few things to note, for example if there are excess assets provided for the repayment:

* The default behavior is that excess assets are supplied to the pool on behalf of `onBehalfOf`. Allows for the user to withdraw the asset on any chain in another transaction.
* `transferExtraAssets` is an option to allow for transferring the excess supplied assets to `onBehalfOf` on Arbitrum instead of doing the default behavior above.

### From Any Chain

{% hint style="warning" %}
When repaying, ensure the [RepletePool](/contracts/repletepool.md) contract has enough allowance to spend funds on behalf of `msg.sender` for the amount being repaid.
{% endhint %}

To repay native token (if supported) through [RepletePool](/contracts/repletepool.md), set the `asset` parameter as `RepletePool.ETH_ADDRESS()` and set `amount` as the intended repay amount. Ensure that `msg.value` covers the bridge transfer fee too. `msg.value` should equal `amount` + `bridgeFee`.

If supplying native is not supported, the function will revert with error `Replete_UnsupportedAsset(address asset)`

#### Interface

#### Stargate v1

{% code fullWidth="true" %}

```solidity
 /**
  * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
  * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
  * @param asset The local address of the borrowed underlying asset
  * @param amount The amount to repay in local asset decimals
  * @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
  * @param onBehalfOf The remote address of the user to repay for on Pool Chain
  * @param transferExtraAssets Option to enable transferring the unbridged assets to `onBehalfOf`
  *  on Pool Chain instead of doing the default behavior (extra assets are supplied to `onBehalOf`).
  * @param stgParams Stargate v1 related bridge parameters
  */
 function repay(
     address asset,
     uint256 amount,
     uint8 interestRateMode,
     address onBehalfOf,
     bool transferExtraAssets,
     StargateSupplyParams calldata stgParams
 ) external payable;
```

{% endcode %}

#### Stargate v2

{% code fullWidth="true" %}

```solidity
 /**
  * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
  * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
  * @param asset The local address of the borrowed underlying asset
  * @param amount The amount to repay in local asset decimals
  * @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
  * @param onBehalfOf The remote address of the user to repay for on Pool Chain
  * @param transferExtraAssets Option to enable transferring the unbridged assets to `onBehalfOf`
  *  on Pool Chain instead of doing the default behavior (extra assets are supplied to `onBehalOf`).
  * @param stgParams Stargate v2 related bridge parameters
  */
 function repay(
     address asset,
     uint256 amount,
     uint8 interestRateMode,
     address onBehalfOf,
     bool transferExtraAssets,
     StargateV2SupplyParams calldata stgParams
 ) external payable returns (Ticket memory);
```

{% endcode %}

#### Example

#### Stargate v1

{% code fullWidth="true" %}

```solidity
RepletePool.repay{value: bridgeFee}({
    asset: address(DAI),                           // local chain DAI address
    amount: 1337 * 1e18,                           // repay 1337 DAI
    interestRateMode: 2,                           // variable debt is being repaid
    onBehalfOf: msg.sender,                        // who is this repayment for
    transferExtraAssets: false,                    // disable the "transferExtraAssets" option
    referralCode: 0,                               // referral code; you can safely set to 0
    stgParams: StargateSupplyParams({              // ~~ Stargate v1 related parameters ~~
        dstGasForCall: 500_000,                    // 500k gas for the destination tx
        dstNativeAmount: 0,                        // native gas airdrop in the destination tx
        dstNativeAddr: RepletePool.destAddress(),  // {BridgeReceiver} address on Pool Chain
        srcPoolId: srcPoolId,                      // source Stargate v1 pool ID
        dstPoolId: dstPoolId,                      // destination Stargate v1 pool ID
        refundAddress: payable(msg.sender),        // refund address
        minAmountLD: 1337 * 1e18                   // set max slippage amount
    })
});
```

{% endcode %}

#### Stargate v2

{% code fullWidth="true" %}

```solidity
RepletePool.repay{value: bridgeFee}({
    asset: address(DAI),                     // local chain DAI address
    amount: 1337 * 1e18,                     // repay 1337 DAI
    interestRateMode: 2,                     // variable debt is being repaid
    onBehalfOf: msg.sender,                  // who is this repayment for
    transferExtraAssets: false,              // disable the "transferExtraAssets" option
    referralCode: 0,                         // referral code; you can safely set to 0
    stgParams: StargateV2SupplyParams({      // ~~ Stargate v2 related parameters ~~
        router: stargateDAIPool,             // Stargate v2 DAI pool address
        extraOptions: extraOptions,          // LZv2 composed message execution options
        oftCmd: "",                          // unused for Stargate taxi transactions 
        refundAddress: payable(msg.sender),  // refund address
        minAmountLD: 1337 * 1e18             // set max slippage amount  
    })
});
```

{% endcode %}


---

# 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.replete.fi/developers/how-to-repay.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.
