Skip to content

Commit

Permalink
add version + ordering to feevault chanopeninit deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed Jun 25, 2024
1 parent 42fcfb0 commit 6fc7939
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 20 deletions.
15 changes: 9 additions & 6 deletions contracts/core/FeeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pragma solidity 0.8.15;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IFeeVault} from "../interfaces/IFeeVault.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {ChannelOrder} from "../libs/Ibc.sol";

contract FeeVault is Ownable, ReentrancyGuard, IFeeVault {
function depositSendPacketFee(
Expand All @@ -35,15 +36,17 @@ contract FeeVault is Ownable, ReentrancyGuard, IFeeVault {
emit SendPacketFeeDeposited(channelId, sequence, gasLimits, gasPrices);
}

function depositOpenChannelFee(address src, string calldata destPortId, string[] calldata connectionHops)
external
payable
nonReentrant
{
function depositOpenChannelFee(
address src,
string memory version,
ChannelOrder ordering,
string[] calldata connectionHops,
string calldata counterpartyPortId
) external payable nonReentrant {
if (msg.value == 0) {
revert NoFeeSent();
}
emit OpenChannelFeeDeposited(src, destPortId, connectionHops, msg.value);
emit OpenChannelFeeDeposited(src, version, ordering, connectionHops, counterpartyPortId, msg.value);
}

function withdrawFeesToOwner() external {
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/Mars.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract Mars is IbcReceiverBase, IbcReceiver, FeeSender {
) external payable onlyOwner {
IbcDispatcher _dispatcher = dispatcher; // cache for gas savings to avoid 2 SLOADS
_dispatcher.channelOpenInit(version, ordering, feeEnabled, connectionHops, counterpartyPortId);
_depositOpenChannelFee(_dispatcher, counterpartyPortId, connectionHops);
_depositOpenChannelFee(_dispatcher, version, ordering, connectionHops, counterpartyPortId);
}

function onRecvPacket(IbcPacket memory packet)
Expand Down
11 changes: 8 additions & 3 deletions contracts/implementation_templates/FeeSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
pragma solidity 0.8.15;

import {IbcDispatcher} from "../interfaces/IbcDispatcher.sol";
import {ChannelOrder} from "../libs/Ibc.sol";

/// Contract with
abstract contract FeeSender {
Expand All @@ -33,9 +34,13 @@ abstract contract FeeSender {

function _depositOpenChannelFee(
IbcDispatcher dispatcher,
string calldata destPortId,
string[] calldata connectionHops
string memory version,
ChannelOrder ordering,
string[] calldata connectionHops,
string calldata counterpartyPortId
) internal {
dispatcher.feeVault().depositOpenChannelFee{value: msg.value}(address(this), destPortId, connectionHops);
dispatcher.feeVault().depositOpenChannelFee{value: msg.value}(
address(this), version, ordering, connectionHops, counterpartyPortId
);
}
}
21 changes: 17 additions & 4 deletions contracts/interfaces/IFeeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

pragma solidity 0.8.15;

import {ChannelOrder} from "../libs/Ibc.sol";

struct GasFee {
uint256 gasLimit;
uint256 gasPrice;
Expand All @@ -29,7 +31,14 @@ struct SendpacketFeeDeposited {

interface IFeeVault {
event SendPacketFeeDeposited(bytes32 channelId, uint64 sequence, uint256[2] gasLimits, uint256[2] gasPrices);
event OpenChannelFeeDeposited(address sourceAddress, string destPortId, string[] connectionHops, uint256 feeAmount);
event OpenChannelFeeDeposited(
address sourceAddress,
string version,
ChannelOrder ordering,
string[] connectionHops,
string counterpartyPortId,
uint256 feeAmount
);

error SenderNotDispatcher();
error NoFeeSent();
Expand All @@ -42,9 +51,13 @@ interface IFeeVault {
uint256[2] calldata gasPrices
) external payable;

function depositOpenChannelFee(address sender, string memory destPortId, string[] calldata connectionHops)
external
payable;
function depositOpenChannelFee(
address sender,
string memory version,
ChannelOrder ordering,
string[] calldata connectionHops,
string memory counterpartyPortId
) external payable;

function withdrawFeesToOwner() external;
}
4 changes: 3 additions & 1 deletion test/Dispatcher/Dispatcher.proof.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ abstract contract DispatcherIbcWithRealProofsSuite is IbcEventsEmitter, Base {
emit ChannelOpenInit(address(mars), "1.0", ChannelOrder.NONE, false, connectionHops1, ch1.portId);

vm.expectEmit(true, true, true, true, address(feeVault));
emit OpenChannelFeeDeposited(address(mars), ch1.portId, connectionHops1, totalOpenChannelFees);
emit OpenChannelFeeDeposited(
address(mars), "1.0", ChannelOrder.NONE, connectionHops1, ch1.portId, totalOpenChannelFees
);
// since this is open chann init, the proof is not used. so use an invalid one
mars.triggerChannelInitWithFee{value: totalOpenChannelFees}(
"1.0", ChannelOrder.NONE, false, connectionHops1, ch1.portId
Expand Down
7 changes: 5 additions & 2 deletions test/upgradeableProxy/DispatcherRC4.upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ contract DispatcherRC4UpgradeTest is DispatcherRC4TestUtils, UpgradeTestUtils {
function setUp() public override {
// In Rc4 version, there can only be one dispatcher per light client so we deploy multiple clients
// Deploy dummy old dispathcer
oldDummyDispatcherProxy = IbcDispatcherRc4(address(deployDispatcherRC4ProxyAndImpl(portPrefix, dummyLightClient))); // we have to manually cast here because solidity is confused by having interfaces coming from seperate files
oldDummyDispatcherProxy =
IbcDispatcherRc4(address(deployDispatcherRC4ProxyAndImpl(portPrefix, dummyLightClient))); // we have to manually
// cast here because solidity is confused by having interfaces coming from seperate files

// Deploy op old dispatcher
DummyLightClient dummyLightClient2 = new DummyLightClient(); // dummyLightClient2 models the op light client in
// prod - it will be the light client that is chosen for the upgrade (and the oldDummyDispatcherProxy will
// be deprecated)
oldDispatcherInterface = IbcDispatcherRc4(address(deployDispatcherRC4ProxyAndImpl(portPrefix, dummyLightClient2)));
oldDispatcherInterface =
IbcDispatcherRc4(address(deployDispatcherRC4ProxyAndImpl(portPrefix, dummyLightClient2)));
dispatcherProxy = IDispatcher(address(oldDispatcherInterface));
uch = deployUCHV2ProxyAndImpl(address(dispatcherProxy));
earth = new EarthRc4(address(uch));
Expand Down
17 changes: 14 additions & 3 deletions test/utils/Dispatcher.base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ contract Base is IbcEventsEmitter, ProofBase, TestUtilsTest {
using stdStorage for StdStorage;

event SendPacketFeeDeposited(bytes32 channelId, uint64 sequence, uint256[2] gasLimits, uint256[2] gasPrices);
event OpenChannelFeeDeposited(address sourceAddress, string destPortId, string[] connectionHops, uint256 fees);
event OpenChannelFeeDeposited(
address sourceAddress,
string version,
ChannelOrder ordering,
string[] connectionHops,
string counterpartyPortId,
uint256 fees
);

uint32 CONNECTION_TO_CLIENT_ID_STARTING_SLOT = 161;
uint32 SEND_PACKET_COMMITMENT_STARTING_SLOT = 156;
Expand Down Expand Up @@ -134,9 +141,13 @@ contract Base is IbcEventsEmitter, ProofBase, TestUtilsTest {
dispatcherProxy.channelOpenInit(le.versionCall, s.ordering, s.feeEnabled, le.connectionHops, re.portId);
if (expPass) {
vm.expectEmit(true, true, true, true, address(feeVault));
emit OpenChannelFeeDeposited(address(le.receiver), re.portId, connectionHops, totalOpenChannelFees);
emit OpenChannelFeeDeposited(
address(le.receiver), le.versionCall, s.ordering, connectionHops, re.portId, totalOpenChannelFees
);
}
feeVault.depositOpenChannelFee{value: totalOpenChannelFees}(address(le.receiver), re.portId, le.connectionHops);
feeVault.depositOpenChannelFee{value: totalOpenChannelFees}(
address(le.receiver), le.versionCall, s.ordering, le.connectionHops, re.portId
);

assertEq(address(feeVault).balance, beforeBalance + totalOpenChannelFees);

Expand Down

0 comments on commit 6fc7939

Please sign in to comment.