How to Repay

When repaying take care to input the correct data. Make sure you are repaying for the correct wallet.

You can repay any supported asset and close borrow positions across any chain through Replete by interacting with RepletePool.

Repaying an asset is often straight forward, where you supply the borrowed asset to repay debt positions. However, if interacting with RepletePool, 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

When repaying, ensure the RepletePool contract has enough allowance to spend funds on behalf of msg.sender for the amount being repaid.

To repay native token (if supported) through RepletePool, 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

 /**
  * @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;

Stargate v2

 /**
  * @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);

Example

Stargate v1

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
    })
});

Stargate v2

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  
    })
});

Last updated