Skip to content

Commit a157dbd

Browse files
authored
onAbort (#587)
1 parent 39218bc commit a157dbd

File tree

1 file changed

+62
-9
lines changed

1 file changed

+62
-9
lines changed

src/pages/developers/chains/zetachain.mdx

+62-9
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ withdraw tokens, use the ZetaChain gateway.
44
The ZetaChain gateway supports:
55

66
- Withdrawing ZRC-20 tokens as native gas or ERC-20 tokens to connected chains.
7-
- Withdrawing ZETA tokens to connected chains.
87
- Withdrawing tokens and making a contract call on connected chains.
98
- Calling contracts on connected chains.
109

10+
Note: Withdrawing ZETA tokens is currently not supported and will revert with
11+
`ZETANotSupported()`.
12+
1113
## Withdraw ZRC-20 Tokens
1214

1315
To withdraw ZRC-20 tokens to an EOA or a contract on a connected chain, use the
@@ -31,7 +33,9 @@ address is chain-agnostic. When withdrawing to an EVM chain, ensure you convert
3133
The `amount` specifies the quantity to withdraw, and `zrc20` is the ZRC-20
3234
address of the token being withdrawn.
3335

34-
You don’t need to specify the destination chain since each ZRC-20 token is tied
36+
The `revertOptions.revertMessage` must not exceed 1024 bytes in length.
37+
38+
You don't need to specify the destination chain since each ZRC-20 token is tied
3539
to the chain from which it was deposited. A ZRC-20 token can only be withdrawn
3640
to its originating chain. For example, to withdraw ZRC-20 USDC.ETH to the BNB
3741
chain, you must first swap it to ZRC-20 USDC.BNB.
@@ -49,6 +53,9 @@ This function withdraws tokens and makes a call to a contract on the connected
4953
chain identified by the `zrc20` address. For instance, if ZRC-20 ETH is
5054
withdrawn, the call is made to a contract on Ethereum.
5155

56+
The combined length of `message` and `revertOptions.revertMessage` must not
57+
exceed 1024 bytes.
58+
5259
## Call a Contract on a Connected Chain
5360

5461
To call a contract on a connected chain without withdrawing tokens, use the
@@ -62,6 +69,9 @@ Here, `zrc20` represents the ZRC-20 token address of the gas token for the
6269
destination chain. This address acts as an identifier for the target chain. For
6370
example, to call a contract on Ethereum, use the ZRC-20 ETH token address.
6471

72+
The combined length of `message` and `revertOptions.revertMessage` must not
73+
exceed 1024 bytes.
74+
6575
## Call Options
6676

6777
The `CallOptions` parameter specifies details for making calls to contracts on
@@ -82,7 +92,7 @@ struct CallOptions {
8292
An arbitrary call invokes any function on a connected chain but does not retain
8393
the original caller's identity—within the target contract, `msg.sender` is the
8494
Gateway address, not the originating universal contract. This is suitable for
85-
scenarios like token swaps, where the callers identity is unnecessary.
95+
scenarios like token swaps, where the caller's identity is unnecessary.
8696

8797
An authenticated call specifically targets the `onCall` function of a contract
8898
on the connected chain. Authentication is achieved because the `onCall` function
@@ -98,7 +108,7 @@ selector and arguments for the target contract:
98108

99109
- **Function Selector**: The first 4 bytes of the Keccak-256 hash of the
100110
function signature.
101-
- **Arguments**: The remaining bytes, ABI-encoded according to Ethereums rules.
111+
- **Arguments**: The remaining bytes, ABI-encoded according to Ethereum's rules.
102112

103113
For example:
104114

@@ -142,8 +152,8 @@ contract is called. If call on revert is false, then a reverted cross-chain
142152
transaction will make a token transfer to the revert address without a contract
143153
call.
144154

145-
`abortAddress` is the address to receive funds on ZetaChain if the CCTX aborts
146-
(this functionality is not implemented yet).
155+
`abortAddress` is an address on ZetaChain, to which tokens are transferred if
156+
reverting failed.
147157

148158
`revertMessage` is a message passed to the `onRevert` function inside the revert
149159
context.
@@ -161,9 +171,9 @@ on which the revert is to be executed. If the deposit amount is insufficient,
161171
the CCTX will abort and `onRevert` will not be called.
162172

163173
Gateway `call` (no asset call) from a connected chain to ZetaChain does not
164-
support reverts, because there are no assets to cover the revert gas costs.
165-
166-
### Revertable Contracts
174+
support reverts, because there are no assets to cover the revert gas costs. If
175+
the execution of `onCall` (as a result of a no-asset `call`) in a universal
176+
contract on ZetaChain reverts, `onAbort` is triggered.
167177

168178
Contracts implementing the `onRevert` function must conform to this interface:
169179

@@ -174,6 +184,7 @@ struct RevertContext {
174184
bytes revertMessage;
175185
}
176186
187+
177188
interface Revertable {
178189
function onRevert(RevertContext calldata revertContext) external;
179190
}
@@ -185,3 +196,45 @@ Gateway's `deposit` or `depositAndCall`. If a gas token was deposited, the
185196

186197
On ZetaChain `asset` is an address of a ZRC-20 withdrawn using Gateway's
187198
`withdraw` or `withdrawAndCall`.
199+
200+
## Abort Transactions
201+
202+
The `abortAddress` field in the `RevertOptions` struct specifies the address on
203+
ZetaChain which is called in two scenarios:
204+
205+
```
206+
Connected chain → ZetaChain, onCall reverts, amount not enough for revert → ZetaChain, onAbort
207+
```
208+
209+
If a cross-chain call from a connected chain to ZetaChain (incoming call) is
210+
reverted, but the amount of tokens supplied with the call is not enough to pay
211+
for a revert transaction back to the source chain. This applies to all no-asset
212+
calls as well as deposit and calls with insufficient amounts.
213+
214+
```
215+
ZetaChain -> Connected chain, onCall reverts → ZetaChain, onRevert reverts → ZetaChain, onAbort
216+
```
217+
218+
When a call from ZetaChain to a connected chain (outgoing call) is reverted, a
219+
cross-chain call was made from connected chain to ZetaChain, which called
220+
`onRevert`, and `onRevert` also reverted.
221+
222+
Tokens are transferred to onAbort address on ZetaChain, and if this address is a
223+
contract it is called.
224+
225+
Contracts implementing the `onAbort` function must conform to this interface:
226+
227+
```solidity
228+
struct AbortContext {
229+
bytes sender;
230+
address asset;
231+
uint256 amount;
232+
bool outgoing;
233+
uint256 chainID;
234+
bytes revertMessage;
235+
}
236+
237+
interface Abortable {
238+
function onAbort(AbortContext calldata abortContext) external;
239+
}
240+
```

0 commit comments

Comments
 (0)