Skip to content

Commit 84cf646

Browse files
authored
chore: further refactor (#1333)
1 parent b9f46b6 commit 84cf646

File tree

10 files changed

+91
-639
lines changed

10 files changed

+91
-639
lines changed

src/content/docs/dev/axelar-sandbox/how-to-use.mdx

-139
This file was deleted.

src/content/docs/dev/axelar-sandbox/intro.mdx

-13
This file was deleted.
+85-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,90 @@
11
# Refund Prepaid Gas
22

3-
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).
3+
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.
44

5-
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.
5+
## Understanding the refund mechanism
66

7-
## Tracking refund status
7+
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.
88

9-
Refund status can be [tracked on Axelarscan](/dev/general-message-passing/monitoring/#1-axelarscan-ui).
9+
Before we dive into the implementation, it's important to understand how refunds work:
10+
11+
1. When you prepay gas using `payNativeGasForContractCall()` or `payNativeGasForContractCallWithToken()`, you might overpay.
12+
1. The excess is refunded if the actual gas used is less than what you paid.
13+
1. The refund is automatically calculated and sent to the specified refund address.
14+
1. Refunds are made on the source chain.
15+
16+
## Specify the refund address
17+
18+
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:
19+
20+
```solidity
21+
function setRemoteValue(
22+
string calldata destinationChain,
23+
string calldata destinationAddress,
24+
string calldata _message
25+
) external payable {
26+
require(msg.value > 0, 'Gas payment is required');
27+
28+
bytes memory payload = abi.encode(_message);
29+
gasService.payNativeGasForContractCall{ value: msg.value }(
30+
address(this),
31+
destinationChain,
32+
destinationAddress,
33+
payload,
34+
msg.sender// This is where the refund address is specified
35+
);
36+
gateway.callContract(destinationChain, destinationAddress, payload);
37+
}
38+
```
39+
40+
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.
41+
42+
## Customize the refund address
43+
44+
You can customize the refund address by replacing `msg.sender` with any valid address. For example:
45+
46+
1. To refund to a specific address:
47+
48+
```solidity
49+
address specificRefundAddress = 0x1234...;
50+
gasService.payNativeGasForContractCall{ value: msg.value }(
51+
52+
// ... other parameters ...
53+
specificRefundAddress
54+
);
55+
```
56+
57+
1. To refund to the contract itself:
58+
59+
```solidity
60+
gasService.payNativeGasForContractCall{ value: msg.value }(
61+
62+
// ... other parameters ...
63+
address(this)
64+
);
65+
66+
```
67+
68+
1. To allow the caller to specify a refund address:
69+
70+
```solidity
71+
function setRemoteValue
72+
// ... other parameters ...
73+
address refundAddress
74+
) external payable {
75+
76+
// ... other code ...
77+
gasService.payNativeGasForContractCall{ value: msg.value }(
78+
79+
// ... other parameters ...
80+
refundAddress
81+
);
82+
// ... other code ...
83+
}
84+
```
85+
86+
## Track the refund status
87+
88+
After specifying the refund address, you can track the refund status on [Axelarscan](https://axelarscan.io/).
89+
90+
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.

src/content/docs/dev/gas-service/specify-gas-refund-address.mdx

-90
This file was deleted.

0 commit comments

Comments
 (0)