-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathIbcReceiver.sol
79 lines (63 loc) · 2.81 KB
/
IbcReceiver.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
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IbcDispatcher} from "./IbcDispatcher.sol";
import {ChannelOrder, ChannelEnd, IbcPacket, AckPacket} from "../libs/Ibc.sol";
/**
* @title IbcChannelReceiver
* @dev This interface must be implemented by IBC-enabled contracts that act as channel owners and process channel
* handshake callbacks.
*/
interface IbcChannelReceiver {
function onChanOpenInit(string calldata version) external returns (string memory selectedVersion);
function onChanOpenTry(string calldata counterpartyVersion) external returns (string memory selectedVersion);
function onChanOpenAck(bytes32 channelId, string calldata counterpartyVersion) external;
function onChanOpenConfirm(bytes32 channelId, string calldata counterpartyVersion) external;
function onCloseIbcChannel(bytes32 channelId, string calldata counterpartyPortId, bytes32 counterpartyChannelId)
external;
}
/**
* @title IbcPacketReceiver
* @notice Packet handler interface must be implemented by a IBC-enabled contract.
* @dev Packet handling callback methods are invoked by the IBC dispatcher.
*/
interface IbcPacketReceiver {
function onRecvPacket(IbcPacket calldata packet) external returns (AckPacket memory ackPacket);
function onAcknowledgementPacket(IbcPacket calldata packet, AckPacket calldata ack) external;
function onTimeoutPacket(IbcPacket calldata packet) external;
}
/**
* @title IbcReceiver
* @author Polymer Labs
* @notice IBC receiver interface must be implemented by a IBC-enabled contract.
* The implementer, aka. dApp devs, should implement channel handshake and packet handling methods.
*/
interface IbcReceiver is IbcChannelReceiver, IbcPacketReceiver {}
contract IbcReceiverBase is Ownable {
IbcDispatcher public dispatcher;
error notIbcDispatcher();
error UnsupportedVersion();
error ChannelNotFound();
/**
* @dev Modifier to restrict access to only the IBC dispatcher.
* Only the address with the IBC_ROLE can execute the function.
* Should add this modifier to all IBC-related callback functions.
*/
modifier onlyIbcDispatcher() {
if (msg.sender != address(dispatcher)) {
revert notIbcDispatcher();
}
_;
}
/**
* @dev Constructor function that takes an IbcDispatcher address and grants the IBC_ROLE to the Polymer IBC
* Dispatcher.
* @param _dispatcher The address of the IbcDispatcher contract.
*/
constructor(IbcDispatcher _dispatcher) Ownable() {
dispatcher = _dispatcher;
}
/// This function is called for plain Ether transfers, i.e. for every call with empty calldata.
// An empty function body is sufficient to receive packet fee refunds.
receive() external payable {}
}