Gas Reimbursement Mechanism

To mitigate high gas fees, VIA Labs offers a gas reimbursement mechanism. This feature allows your BridgedManagerV1 contract to replenish lost gas. It does so by swapping USDC collected from users for the wrapped native gas coin (WETH) using a semi-automated function. This mechanism can be enabled for any blockchain with a UniswapV2-compatible DEX and adequate USDC / Bridged USDC liquidity.

Automatic Scripting

VIA Labs can provide you with an automatic script that regularly monitors the WETH balance of a specified Bridged Manager contract and automatically invokes the swapGas function to swap USDC for WETH when the balance falls below a set threshold and reimbursements are available. Designed to run continuously (e.g., as a cron job), it ensures the contract maintains sufficient gas tokens to support the automatic relaying of cross-chain messages. Please contact us if you would like to receive the automatic script.

Blockchain Responsibilities and Options

Manage Gas Token Balance

  • Monitor the WETH balance of your Bridged Manager contract.

  • Use swapGas() to replenish the WETH balance when necessary.

Configure WETH Settings

  • Use setWeth() to update the WETH token address and the base amount of WETH.

Further Reading - How it Works

The example below assumes the Bridged USDC Standard with the host / root chain chosen as Ethereum.

  1. Deducting Gas: When a user sends a transaction from your blockchain to Ethereum, the system estimates the gas required (WETH) to process the message and deduct that specific amount from the user's transfer in USDC. The USDC is then reserved in the BridgedManagerV1 contract on the host chain.

  2. WETH Balance Depletion: As gas fees are paid in WETH, the contract's WETH balance decreases over time.

  3. Replenishment via swapGas(): When the WETH balance is low, you can call the swapGas() function to replenish the WETH balance by swapping the accumulated USDC reimbursements for WETH.

Key Functions

1. swapGas() Function

This function swaps the accumulated USDC reimbursements for WETH to replenish the contract's gas token balance.

Usage

function swapGas(uint256 minAmountOutInWETH) public onlySwapper
  • minAmountOutInWETH: The minimum amount of WETH expected from the swap to protect against slippage or MEV.

When to Call

  • Whenever the contract's WETH balance is below the desired threshold (this can be any amount that you want).

  • Regularly, based on transaction volume and gas consumption.

Requirements

  • The contract must have accumulated USDC reimbursements (REIMBURSEMENTS > 0).

  • The swapGas() function must be called by an address with the onlySwapper role.

2. setWeth() Function

This function allows you to set the base amount (BASE_AMOUNT) of WETH that the contract should maintain.

Usage

function setWeth(uint256 customBaseAmount) public onlyOwner
  • customBaseAmount: The desired base amount of WETH to maintain.

Default Setting (customBaseAmount = 0)

  • If customBaseAmount is set to 0, the function will automatically set BASE_AMOUNT to the contract's current WETH Balance.

Custom Setting (customBaseAmount > 0)

  • If customBaseAmount is provided and is lower than the current WETH balance, the function will set BASE_AMOUNT to this custom value.

  • With a custom BASE_AMOUNT, the contract will sponsor gas reimbursements for users until the WETH balance decreases to the specified BASE_AMOUNT.

  • Once the WETH balance reaches the BASE_AMOUNT, users resume being charged for gas reimbursements.

This flexibility allows you to manage how much WETH the contract holds and control when gas reimbursements are provided to users.

When to Call

  • Upon deployment of the contract to set up the WETH address and base amount.

Last updated