Skip to content

chore: further refactor #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 0 additions & 139 deletions src/content/docs/dev/axelar-sandbox/how-to-use.mdx

This file was deleted.

13 changes: 0 additions & 13 deletions src/content/docs/dev/axelar-sandbox/intro.mdx

This file was deleted.

89 changes: 85 additions & 4 deletions src/content/docs/dev/gas-service/refund.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,90 @@
# Refund Prepaid Gas

If the gas fees prepaid to `payNativeGasForContractCall()` or `payNativeGasForContractCallWithToken()` exceeds the actual amount needed for relaying a message to the destination contract, the Gas Service will automatically calculate the excess gas amount and refund it to the payer’s wallet address by calling `refund()` on the [`AxelarGasService` contract](https://github.com/axelarnetwork/axelar-gmp-sdk-solidity/blob/ad37802dc6d62fff3ab589f2605f7a3e566977dd/contracts/interfaces/IAxelarGasService.sol).
When using [Axelar's General Message Passing (GMP)](/dev/general-message-passing/overview/) for multichain communication, you can specify a refund address for unused gas. [Axelar's Gas Service](/dev/gas-service/intro/), with an off-chain relayer implementation, refunds any unused gas to a specified refund address. Here's a guide on how to specify this refund address in your Solidity contract.

The refunded amount consists of the total amount paid, minus the network base fee, the actual gas used, and the gas costs estimated for transferring the refund. Refunds are made on the source chain.
## Understanding the refund mechanism

## Tracking refund status
Axelar allows users to prepay gas fees required for relaying messages or executing smart contracts across different blockchains. If the gas paid exceeds the actual amount used, the excess is refunded to the sender's address. You can set the refund address in your contract when paying for the gas to direct this refund to a specific address.

Refund status can be [tracked on Axelarscan](/dev/general-message-passing/monitoring/#1-axelarscan-ui).
Before we dive into the implementation, it's important to understand how refunds work:

1. When you prepay gas using `payNativeGasForContractCall()` or `payNativeGasForContractCallWithToken()`, you might overpay.
1. The excess is refunded if the actual gas used is less than what you paid.
1. The refund is automatically calculated and sent to the specified refund address.
1. Refunds are made on the source chain.

## Specify the refund address

In this [`CallContract`](https://github.com/axelarnetwork/axelar-examples/blob/main/examples/evm/call-contract/CallContract.sol) [example](https://github.com/axelarnetwork/axelar-examples/tree/main/examples/evm/call-contract) the refund address is specified in the `setRemoteValue` function:

```solidity
function setRemoteValue(
string calldata destinationChain,
string calldata destinationAddress,
string calldata _message
) external payable {
require(msg.value > 0, 'Gas payment is required');

bytes memory payload = abi.encode(_message);
gasService.payNativeGasForContractCall{ value: msg.value }(
address(this),
destinationChain,
destinationAddress,
payload,
msg.sender// This is where the refund address is specified
);
gateway.callContract(destinationChain, destinationAddress, payload);
}
```

The last parameter of `payNativeGasForContractCall()` is the refund address. In this case, it's set to `msg.sender`, meaning any refund will go to the address that called the `setRemoteValue()` function.

## Customize the refund address

You can customize the refund address by replacing `msg.sender` with any valid address. For example:

1. To refund to a specific address:

```solidity
address specificRefundAddress = 0x1234...;
gasService.payNativeGasForContractCall{ value: msg.value }(

// ... other parameters ...
specificRefundAddress
);
```

1. To refund to the contract itself:

```solidity
gasService.payNativeGasForContractCall{ value: msg.value }(

// ... other parameters ...
address(this)
);

```

1. To allow the caller to specify a refund address:

```solidity
function setRemoteValue
// ... other parameters ...
address refundAddress
) external payable {

// ... other code ...
gasService.payNativeGasForContractCall{ value: msg.value }(

// ... other parameters ...
refundAddress
);
// ... other code ...
}
```

## Track the refund status

After specifying the refund address, you can track the refund status on [Axelarscan](https://axelarscan.io/).

Choosing the correct refund address is important for your contract's functionality and user experience. Always ensure that the refund address is valid and accessible.
90 changes: 0 additions & 90 deletions src/content/docs/dev/gas-service/specify-gas-refund-address.mdx

This file was deleted.

Loading