Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MockAxelarGasService

Git Source

Inherits: InterchainGasEstimation, Upgradable, IAxelarGasService

Title: AxelarGasService

This contract manages gas payments and refunds for cross-chain communication on the Axelar network.

The owner address of this contract should be the microservice that pays for gas.

Users pay gas for cross-chain calls, and the gasCollector can collect accumulated fees and/or refund users if needed.

State Variables

gasCollector

address public immutable gasCollector

Functions

constructor

Constructs the AxelarGasService contract.

constructor(address gasCollector_) ;

Parameters

NameTypeDescription
gasCollector_addressThe address of the gas collector

_setup

function _setup(bytes calldata data) internal override;

onlyCollector

Modifier that ensures the caller is the designated gas collector.

modifier onlyCollector() ;

payGas

Pay for gas for any type of contract execution on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

If estimateOnChain is true, the function will estimate the gas cost and revert if the payment is insufficient.

function payGas(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    uint256 executionGasLimit,
    bool estimateOnChain,
    address refundAddress,
    bytes calldata params
) external payable override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call
executionGasLimituint256The gas limit for the contract call
estimateOnChainboolFlag to enable on-chain gas estimation
refundAddressaddressThe address where refunds, if any, should be sent
paramsbytesAdditional parameters for gas payment

payGasForContractCall

Pay for gas using ERC20 tokens for a contract call on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

function payGasForContractCall(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    address gasToken,
    uint256 gasFeeAmount,
    address refundAddress
) external override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call
gasTokenaddressThe address of the ERC20 token used to pay for gas
gasFeeAmountuint256The amount of tokens to pay for gas
refundAddressaddressThe address where refunds, if any, should be sent

payGasForContractCallWithToken

Pay for gas using ERC20 tokens for a contract call with tokens on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

function payGasForContractCallWithToken(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    string memory symbol,
    uint256 amount,
    address gasToken,
    uint256 gasFeeAmount,
    address refundAddress
) external override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call with tokens will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call with tokens
symbolstringThe symbol of the token to be sent with the call
amountuint256The amount of tokens to be sent with the call
gasTokenaddressThe address of the ERC20 token used to pay for gas
gasFeeAmountuint256The amount of tokens to pay for gas
refundAddressaddressThe address where refunds, if any, should be sent

payNativeGasForContractCall

Pay for gas using native currency for a contract call on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

function payNativeGasForContractCall(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    address refundAddress
) external payable override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call
refundAddressaddressThe address where refunds, if any, should be sent

payNativeGasForContractCallWithToken

Pay for gas using native currency for a contract call with tokens on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

function payNativeGasForContractCallWithToken(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    string calldata symbol,
    uint256 amount,
    address refundAddress
) external payable override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call with tokens will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call with tokens
symbolstringThe symbol of the token to be sent with the call
amountuint256The amount of tokens to be sent with the call
refundAddressaddressThe address where refunds, if any, should be sent

payGasForExpressCall

Pay for gas using ERC20 tokens for an express contract call on a destination chain.

This function is called on the source chain before calling the gateway to express execute a remote contract.

function payGasForExpressCall(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    address gasToken,
    uint256 gasFeeAmount,
    address refundAddress
) external override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call
gasTokenaddressThe address of the ERC20 token used to pay for gas
gasFeeAmountuint256The amount of tokens to pay for gas
refundAddressaddressThe address where refunds, if any, should be sent

payGasForExpressCallWithToken

Pay for gas using ERC20 tokens for an express contract call with tokens on a destination chain.

This function is called on the source chain before calling the gateway to express execute a remote contract.

function payGasForExpressCallWithToken(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    string memory symbol,
    uint256 amount,
    address gasToken,
    uint256 gasFeeAmount,
    address refundAddress
) external override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call with tokens will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call with tokens
symbolstringThe symbol of the token to be sent with the call
amountuint256The amount of tokens to be sent with the call
gasTokenaddressThe address of the ERC20 token used to pay for gas
gasFeeAmountuint256The amount of tokens to pay for gas
refundAddressaddressThe address where refunds, if any, should be sent

payNativeGasForExpressCall

Pay for gas using native currency for an express contract call on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

function payNativeGasForExpressCall(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    address refundAddress
) external payable override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call
refundAddressaddressThe address where refunds, if any, should be sent

payNativeGasForExpressCallWithToken

Pay for gas using native currency for an express contract call with tokens on a destination chain.

This function is called on the source chain before calling the gateway to execute a remote contract.

function payNativeGasForExpressCallWithToken(
    address sender,
    string calldata destinationChain,
    string calldata destinationAddress,
    bytes calldata payload,
    string calldata symbol,
    uint256 amount,
    address refundAddress
) external payable override;

Parameters

NameTypeDescription
senderaddressThe address making the payment
destinationChainstringThe target chain where the contract call with tokens will be made
destinationAddressstringThe target address on the destination chain
payloadbytesData payload for the contract call with tokens
symbolstringThe symbol of the token to be sent with the call
amountuint256The amount of tokens to be sent with the call
refundAddressaddressThe address where refunds, if any, should be sent

addGas

Add additional gas payment using ERC20 tokens after initiating a cross-chain call.

This function can be called on the source chain after calling the gateway to execute a remote contract.

function addGas(bytes32 txHash, uint256 logIndex, address gasToken, uint256 gasFeeAmount, address refundAddress)
    external
    override;

Parameters

NameTypeDescription
txHashbytes32The transaction hash of the cross-chain call
logIndexuint256The log index for the cross-chain call
gasTokenaddressThe ERC20 token address used to add gas
gasFeeAmountuint256The amount of tokens to add as gas
refundAddressaddressThe address where refunds, if any, should be sent

addNativeGas

Add additional gas payment using native currency after initiating a cross-chain call.

This function can be called on the source chain after calling the gateway to execute a remote contract.

function addNativeGas(bytes32 txHash, uint256 logIndex, address refundAddress) external payable override;

Parameters

NameTypeDescription
txHashbytes32The transaction hash of the cross-chain call
logIndexuint256The log index for the cross-chain call
refundAddressaddressThe address where refunds, if any, should be sent

addExpressGas

Add additional gas payment using ERC20 tokens after initiating an express cross-chain call.

This function can be called on the source chain after calling the gateway to express execute a remote contract.

function addExpressGas(
    bytes32 txHash,
    uint256 logIndex,
    address gasToken,
    uint256 gasFeeAmount,
    address refundAddress
) external override;

Parameters

NameTypeDescription
txHashbytes32The transaction hash of the cross-chain call
logIndexuint256The log index for the cross-chain call
gasTokenaddressThe ERC20 token address used to add gas
gasFeeAmountuint256The amount of tokens to add as gas
refundAddressaddressThe address where refunds, if any, should be sent

addNativeExpressGas

Add additional gas payment using native currency after initiating an express cross-chain call.

This function can be called on the source chain after calling the gateway to express execute a remote contract.

function addNativeExpressGas(bytes32 txHash, uint256 logIndex, address refundAddress) external payable override;

Parameters

NameTypeDescription
txHashbytes32The transaction hash of the cross-chain call
logIndexuint256The log index for the cross-chain call
refundAddressaddressThe address where refunds, if any, should be sent

updateGasInfo

Updates the gas price for a specific chain.

This function is called by the gas oracle to update the gas prices for a specific chains.

function updateGasInfo(string[] calldata chains, GasInfo[] calldata gasUpdates) external onlyCollector;

Parameters

NameTypeDescription
chainsstring[]Array of chain names
gasUpdatesGasInfo[]Array of gas updates

collectFees

Allows the gasCollector to collect accumulated fees from the contract.

Use address(0) as the token address for native currency.

function collectFees(address payable receiver, address[] calldata tokens, uint256[] calldata amounts)
    external
    onlyCollector;

Parameters

NameTypeDescription
receiveraddress payableThe address to receive the collected fees
tokensaddress[]Array of token addresses to be collected
amountsuint256[]Array of amounts to be collected for each respective token address

refund

Deprecated refund function, kept for backward compatibility.

function refund(address payable receiver, address token, uint256 amount) external onlyCollector;

refund

Refunds gas payment to the receiver in relation to a specific cross-chain transaction.

Only callable by the gasCollector.

Use address(0) as the token address to refund native currency.

function refund(bytes32 txHash, uint256 logIndex, address payable receiver, address token, uint256 amount)
    external
    onlyCollector;

Parameters

NameTypeDescription
txHashbytes32The transaction hash of the cross-chain call
logIndexuint256The log index for the cross-chain call
receiveraddress payableThe address to receive the refund
tokenaddressThe token address to be refunded
amountuint256The amount to refund

_refund

Internal function to implement gas refund logic.

function _refund(bytes32 txHash, uint256 logIndex, address payable receiver, address token, uint256 amount)
    private;

contractId

Returns a unique identifier for the contract.

function contractId() external pure returns (bytes32);

Returns

NameTypeDescription
<none>bytes32bytes32 Hash of the contract identifier