/
ZetaInterfaces.sol
110 lines (97 loc) · 4.07 KB
/
ZetaInterfaces.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
interface ZetaInterfaces {
/**
* @dev Use SendInput to interact with the Connector: connector.send(SendInput)
*/
struct SendInput {
/// @dev Chain id of the destination chain. More about chain ids https://docs.zetachain.com/learn/glossary#chain-id
uint256 destinationChainId;
/// @dev Address receiving the message on the destination chain (expressed in bytes since it can be non-EVM)
bytes destinationAddress;
/// @dev Gas limit for the destination chain's transaction
uint256 destinationGasLimit;
/// @dev An encoded, arbitrary message to be parsed by the destination contract
bytes message;
/// @dev ZETA to be sent cross-chain + ZetaChain gas fees + destination chain gas fees (expressed in ZETA)
uint256 zetaValueAndGas;
/// @dev Optional parameters for the ZetaChain protocol
bytes zetaParams;
}
/**
* @dev Our Connector calls onZetaMessage with this struct as argument
*/
struct ZetaMessage {
bytes zetaTxSenderAddress;
uint256 sourceChainId;
address destinationAddress;
/// @dev Remaining ZETA from zetaValueAndGas after subtracting ZetaChain gas fees and destination gas fees
uint256 zetaValue;
bytes message;
}
/**
* @dev Our Connector calls onZetaRevert with this struct as argument
*/
struct ZetaRevert {
address zetaTxSenderAddress;
uint256 sourceChainId;
bytes destinationAddress;
uint256 destinationChainId;
/// @dev Equals to: zetaValueAndGas - ZetaChain gas fees - destination chain gas fees - source chain revert tx gas fees
uint256 remainingZetaValue;
bytes message;
}
}
interface ZetaConnector {
/**
* @dev Sending value and data cross-chain is as easy as calling connector.send(SendInput)
*/
function send(ZetaInterfaces.SendInput calldata input) external;
}
interface ZetaReceiver {
/**
* @dev onZetaMessage is called when a cross-chain message reaches a contract
*/
function onZetaMessage(ZetaInterfaces.ZetaMessage calldata zetaMessage) external;
/**
* @dev onZetaRevert is called when a cross-chain message reverts.
* It's useful to rollback to the original state
*/
function onZetaRevert(ZetaInterfaces.ZetaRevert calldata zetaRevert) external;
}
/**
* @dev ZetaTokenConsumer makes it easier to handle the following situations:
* - Getting Zeta using native coin (to pay for destination gas while using `connector.send`)
* - Getting Zeta using a token (to pay for destination gas while using `connector.send`)
* - Getting native coin using Zeta (to return unused destination gas when `onZetaRevert` is executed)
* - Getting a token using Zeta (to return unused destination gas when `onZetaRevert` is executed)
* @dev The interface can be implemented using different strategies, like UniswapV2, UniswapV3, etc
*/
interface ZetaTokenConsumer {
event EthExchangedForZeta(uint256 amountIn, uint256 amountOut);
event TokenExchangedForZeta(address token, uint256 amountIn, uint256 amountOut);
event ZetaExchangedForEth(uint256 amountIn, uint256 amountOut);
event ZetaExchangedForToken(address token, uint256 amountIn, uint256 amountOut);
function getZetaFromEth(address destinationAddress, uint256 minAmountOut) external payable returns (uint256);
function getZetaFromToken(
address destinationAddress,
uint256 minAmountOut,
address inputToken,
uint256 inputTokenAmount
) external returns (uint256);
function getEthFromZeta(
address destinationAddress,
uint256 minAmountOut,
uint256 zetaTokenAmount
) external returns (uint256);
function getTokenFromZeta(
address destinationAddress,
uint256 minAmountOut,
address outputToken,
uint256 zetaTokenAmount
) external returns (uint256);
function hasZetaLiquidity() external view returns (bool);
}
interface ZetaCommonErrors {
error InvalidAddress();
}