Skip to content

Commit

Permalink
change gasLimits and gasPrices from calldata to memory in example con…
Browse files Browse the repository at this point in the history
…tracts
  • Loading branch information
RnkSngh committed Jul 18, 2024
1 parent 7064fc8 commit 78522c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
4 changes: 2 additions & 2 deletions contracts/base/GeneralMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ contract GeneralMiddleware is IbcMwUser, IbcMiddleware, IbcMwEventsEmitter, IbcM
bytes32 destPortAddr,
bytes calldata appData,
uint64 timeoutTimestamp,
uint256[2] calldata gasLimits,
uint256[2] calldata gasPrices
uint256[2] memory gasLimits,
uint256[2] memory gasPrices
) external payable override returns (uint64 sequence) {}

function sendMWPacket(
Expand Down
34 changes: 11 additions & 23 deletions contracts/examples/Mars.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,9 @@ contract Mars is IbcReceiverBase, IbcReceiver, FeeSender {

/**
* @notice Callback for acknowledging a packet; triggered on reciept of an IBC packet by the counterparty
* @param packet The IBC packet for which acknowledgement is received
* @param ack The acknowledgement packet received
* @dev Make sure to validate packet's source and destiation channels and ports.
*/
function onAcknowledgementPacket(IbcPacket calldata packet, AckPacket calldata ack)
external
virtual
onlyIbcDispatcher
{
function onAcknowledgementPacket(IbcPacket calldata, AckPacket calldata ack) external virtual onlyIbcDispatcher {
ackPackets.push(ack);
}

Expand All @@ -119,14 +113,8 @@ contract Mars is IbcReceiverBase, IbcReceiver, FeeSender {
* @notice Handles channel close callback on the dest chain
* @param channelId The unique identifier of the channel
* @dev Make sure to validate channelId and counterpartyVersion
* @param counterpartyPortId The unique identifier of the counterparty's port
* @param counterpartyChannelId The unique identifier of the counterparty's channel
*/
function onChanCloseConfirm(bytes32 channelId, string calldata counterpartyPortId, bytes32 counterpartyChannelId)
external
virtual
onlyIbcDispatcher
{
function onChanCloseConfirm(bytes32 channelId, string calldata, bytes32) external virtual onlyIbcDispatcher {
// logic to determine if the channel should be closed
bool channelFound = false;
for (uint256 i = 0; i < connectedChannels.length; i++) {
Expand Down Expand Up @@ -182,8 +170,8 @@ contract Mars is IbcReceiverBase, IbcReceiver, FeeSender {
string calldata message,
bytes32 channelId,
uint64 timeoutTimestamp,
uint256[2] calldata gasLimits,
uint256[2] calldata gasPrices
uint256[2] memory gasLimits,
uint256[2] memory gasPrices
) external payable returns (uint64 sequence) {
sequence = dispatcher.sendPacket(channelId, bytes(message), timeoutTimestamp);
_depositSendPacketFee(dispatcher, channelId, sequence, gasLimits, gasPrices);
Expand All @@ -192,15 +180,15 @@ contract Mars is IbcReceiverBase, IbcReceiver, FeeSender {
/**
* @notice Handles the channel close init event
* @dev Make sure to validate channelId and counterpartyVersion
* @param counterpartyPortIdentifier The unique identifier of the counterparty's channel
* @param version The channel version
*/
function onChanOpenInit(
ChannelOrder,
string[] calldata,
string calldata counterpartyPortIdentifier,
string calldata version
) external view virtual onlyIbcDispatcher returns (string memory selectedVersion) {
function onChanOpenInit(ChannelOrder, string[] calldata, string calldata, string calldata version)
external
view
virtual
onlyIbcDispatcher
returns (string memory selectedVersion)
{
return _openChannel(version);
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/implementation_templates/FeeSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ abstract contract FeeSender {
* - gasPrices[1] for `ackPacket` fees, for the src chain
* @notice The total fees sent in the msg.value should be equal to the total gasLimits[0] * gasPrices[0] +
* @notice Use the Polymer fee estimation api to get the required fees to ensure that enough fees are sent.
* @dev Note: We have to have gasLimits and gasPrices as memory arrays. We cannot have them as calldata arrays
* because solidity has weird behavior with using too much calldata in stacked calls
* gasLimits[1] * gasPrices[1]. The transaction will revert if a higher or lower value is sent
*/
function _depositSendPacketFee(
IbcDispatcher dispatcher,
bytes32 channelId,
uint64 sequence,
uint256[2] calldata gasLimits,
uint256[2] calldata gasPrices
uint256[2] memory gasLimits,
uint256[2] memory gasPrices
) internal {
dispatcher.feeVault().depositSendPacketFee{value: msg.value}(channelId, sequence, gasLimits, gasPrices);
}
Expand Down

0 comments on commit 78522c0

Please sign in to comment.